ASP.Net MVC Json Result: Parameters passed to controller method issue
Posted
by Moskie
on Stack Overflow
See other posts from Stack Overflow
or by Moskie
Published on 2009-03-18T19:54:47Z
Indexed on
2010/03/22
3:11 UTC
Read the original article
Hit count: 440
I'm having a problem getting a controller method that returns a JsonResult to accept parameters passed via the JQuery getJSON method.
The code I’m working on works fine when the second parameter ("data") of the getJSON method call is null. But when I attempt to pass in a value there, it seems as if the controller method never even gets called.
In this example case, I just want to use an integer. The getJSON call that works fine looks like this:
$.getJSON(”/News/ListNewsJson/”, null, ListNews_OnReturn);
The controller method is like this:
public JsonResult ListNewsJson(int? id)
{
…
return Json(toReturn);
}
By putting a breakpoint in the ListNewsJson method, I see that this method gets called when the data parameter of getJSON is null, but when I replace it with value, such as, say, 3:
$.getJSON(”/News/ListNewsJson/”, 3, ListNews_OnReturn);
… the controller method/breakpoint is never hit. Any idea what I'm doing wrong?
I should also mention that the controller method works fine if I manually go to the address via my browser ("/News/ListNewsJson/3").
© Stack Overflow or respective owner