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?
I am trying to create controller actions which will return either JSON or partial
Share
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.
If you want to return a plain string, you can just use the ContentResult:
ContentResult by default returns a text/plain as its contentType.
This is overloadable so you can also do: