Actionresult vs JSONresult

后端 未结 5 1210
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 07:07

I have 2 questions:

  1. What is the difference between JSONResult and ActionResult?

  2. When to use JSONResult in MVC?

5条回答
  •  抹茶落季
    2020-12-14 07:13

    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.

提交回复
热议问题