MVC5 controller action not called from JSON AJAX Post

后端 未结 2 1523
情话喂你
情话喂你 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:18

    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.

提交回复
热议问题