MVC5 controller action not called from JSON AJAX Post

后端 未结 2 1516
情话喂你
情话喂你 2020-12-12 05:41

I am sending data from from a javascript app to a MVC5 controller, however when data is submitted to the Submit controller action, it is never called. I have some very simpl

2条回答
  •  [愿得一人]
    2020-12-12 06:24

    You will have to make two changes: Stringify your Json as below:

    $.ajax({
        cache: false,
        url: url,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: JSON.stringify(item),
        type: 'POST',
        success: function (data, textStatus, jqXHR) {           
        },
        error: function (data, textStatus, jqXHR) { 
        }
    });
    

    Second, Just Annotate your Method with [HttpPost] as below:

    [HttpPost]
    public JsonResult Submit(string[] Skus, ContactDto Contact)
    {
        return Json(new { success = true, message = "Some message" });
    }
    

提交回复
热议问题