Actionresult 与 JSONresult [英] Actionresult vs JSONresult
问题描述
我有两个问题:
<块引用>JSONResult 和 ActionResult 有什么区别?
什么时候在 MVC 中使用 JSONResult?
ActionResult
是一个动作可以返回的抽象类.
Controller
中的辅助方法(例如,Json()
、Content()
、View()
, ...) 返回不同的继承 ActionResult
的具体类,包括 JsonResult
.
您应该将操作方法声明为返回 ActionResult
,以便它们可以自由地返回任何具体的结果类.
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.
这篇关于Actionresult 与 JSONresult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!