Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 控制器未恢复Ajax值_Jquery_.net_Ajax_Model View Controller - Fatal编程技术网

Jquery 控制器未恢复Ajax值

Jquery 控制器未恢复Ajax值,jquery,.net,ajax,model-view-controller,Jquery,.net,Ajax,Model View Controller,我知道这个问题已经被问过很多次了,我确信我错过了一些非常简单的事情,但我整天都在坚持这个问题,不知道为什么会这样。到目前为止,我的代码是: $(document).ready(function() { $(this).on("click", "#submitBtn", function() { var textValue = $('.croppedImg').attr("src"); $.ajax({ type: 'POS

我知道这个问题已经被问过很多次了,我确信我错过了一些非常简单的事情,但我整天都在坚持这个问题,不知道为什么会这样。到目前为止,我的代码是:

$(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"}};
}

您不需要javascript中的新关键字。如果没有新的关键字,它就会出错。非常感谢你,我真不敢相信我被这么愚蠢的事情困了一整天。