Home > DeveloperSection > Forums > When sending jQuery post to MVC controller getting 404 error
Ankit Singh

Total Post:341

Points:2389
Posted on    May-21-2015 6:54 AM

 JQuery Mvc  Controller  Error 
Ratings:


 1 Reply(s)
 456  View(s)
Rate this:

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)

{

       ...

}



Tanuj Kumar

Total Post:134

Points:940
Posted on    May-21-2015 7:50 AM

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).


Don't want to miss updates? Please click the below button!

Follow MindStick