I am converting an existing ASP.NET application to MVC2, and I have an existing method that is called through jQuery using Ajax, which worked before, but does not work now. Therefore, it seems that there are some changes that I need to make due to the use of MVC2, which I cannot understand.
I have reduced the complexity of the code, but it still does not work. This is my current code:
jQuery script that runs when a button is clicked
function leaveComment() { if (validate()) { $.ajax({ type: "POST", url: "/Pages/PostBlogComment", data: "{'name':'Test','url':'Test','email':'Test','body':'Test','postid':'Test'}", dataType: "json", success: function (msg) {
};
Inside my controller called Pages, I created the following method:
public string PostBlogComment( string name, string url, string email, string body, string postid) { return "This is a test"; }
When debugging, I see that the PostBlogComment method is called, but there are two main problems that I encountered:
- All method arguments are accepted as null, so I have no useful data to work with. For testing, now all arguments are sent as
Test , as you can see from the code. - When the result is returned to the Ajax method, the error path is called, not the success path, even if the method really returned the string as usual (even if the parameters sent were empty)
The error is probably easy to spot for those who regularly work with these things (or at least I hope so):