我知道这个问题已经被问到很多次了,我敢肯定,我缺少一些非常简单的东西,但是我整天都坚持这一问题,并且不知道为什么会发生这种情况。到目前为止,我的代码:
$(document).ready(function() {
$(this).on("click",
"#submitBtn",
function() {
var textValue = $('.croppedImg').attr("src");
$.ajax({
type: 'POST',
url: '/user/myprofile/updateavatar',
data: textValue,
success: function(data) {
location.reload();
}
});
});
})
和控制器:
[HttpPost]
public virtual ActionResult UpdateAvatar(string textValue)
{
//some code
return new JsonResult {Data = new {Status = "success"}};
}
我已经与Fiddler进行了检查,并且Ajax调用正在向控制器发送一个字符串,但是每次尝试调试时,我都会获得TextValue的无效值。谢谢您的帮助
尝试此
$(document).ready(function() {
$(this).on("click",
"#submitBtn",
function() {
var textValue = $('.croppedImg').attr("src");
$.ajax({
type: 'POST',
url: '/user/myprofile/updateavatar',
data: {textValue : textValue } ,
success: function(data) {
location.reload();
}
});
});
})
也许使用
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult UpdateAvatar(string textValue)
{
return new JsonResult {Data = new {Status = "success"}};
}