Actionresult vs JSONresult

I have 2 questions:

  • What is the difference between JSONResult and ActionResult?

  • When to use JSONResult in MVC?


  • ActionResult is an abstract class that an action can return.

    The helper methods in Controller (eg, Json() , Content() , View() , ...) return different concrete classes that inherit ActionResult , including JsonResult .

    You should declare your action methods as returning ActionResult , so that they have the freedom to return any concrete result class.


    Use JsonResult when you want to return raw JSON data to be consumed by a client (javascript on a web page or a mobile client).

    Use ActionResult if you want to return a view, redirect etc to be handled by a browser.


    ActionResult is an abstract class . JsonResult is subtype of ActionResult . So we can return json content in both types.

    链接地址: http://www.djcxy.com/p/47822.html

    上一篇: 从Facebook Graph API获取用户的名字

    下一篇: ActionResult vs JSONresult