I am trying to create controller actions which will return either JSON or partial html depending upon a parameter. What is the best way to get the result returned to an MVC page asynchronously?
![]() ![]() ![]()
8
|
|
add comment
|
![]() ![]() ![]() |
In your action method, return Json(object) to return JSON to your page.
Then just call the action method using Ajax. You could use one of the helper methods from the ViewPage such as
SomeMethod would be a javascript method that then evaluates the Json object returned. Phil |
||
![]() ![]() |
Another nice way to deal with JSON data is using the JQuery getJSON function. You can call the
method from the jquery getJSON method by simply...
|
||
![]() ![]() |
To answer the other half of the question, you can call:
when you want to return partial HTML. You'll just have to find some way to decide whether the request wants JSON or HTML, perhaps based on a URL part/parameter. |
||