When sending jQuery post to MVC controller getting 404 error

I'm sending from view using jQuery to MVC post action

function DoSomething(passedId) {
                    $.ajax({
                        method: "POST",
                        dataType: 'text',
                        url: '/MyController/SomeAction/',
                        data: { id: passedId }
                    }).done(function (data) {
                        //                       
                    });
                }

And inside MyController

[HttpPost]
public ActionResult SomeAction(int id)
{
       ...
}
Last updated:5/21/2015 7:50:03 AM

1 Answers

Anonymous User
Anonymous User

You didn't said which version of jquery you are using. Please check jquery version and in case that this version is < 1.9.0 you should instead of

Method: ”post”

Use

Type: ”post”

this is an alias for method, and according to jquery official documentation you should use type if you're using versions of jQuery prior to 1.9.0.

function DoSomething(passedId) {    
                    $.ajax({
                        type: 'POST',
                        dataType: 'text',                      
                        url: '/MyController/SomeAction/',
                        data: { id: passedId}
                    }).done(function (data) {                                       
                        ...
                    });
                }

Tested above code and it works (each request enter inside mvc controller http post SomeAction action).

Answer