Mvc5 Controller Action Not Called From Json Ajax Post
Solution 1:
Four things you must check using ajax calls, 1. If using javascript object you must stringify the object before passing. 2. The Action verb for the action method should be same as the type of your ajax call if POST then the action method should be decorated by action verb [HttpPost]. 3. Always use the relative path for url's in ajax as @Url.Action("action", "controller"). 4. The input parameters of your action method method should match the json object parameters (exactly i.e. case sensitive).
For debugging you may use firebug addon in your browser so that you can see what is sent over the network or press F12 for debugging tool in that check in network tab.
Solution 2:
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" });
}
Post a Comment for "Mvc5 Controller Action Not Called From Json Ajax Post"