Actionresult 与 JSONresult [英] Actionresult vs JSONresult

查看:63
本文介绍了Actionresult 与 JSONresult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:

<块引用>

  1. JSONResult 和 ActionResult 有什么区别?

  2. 什么时候在 MVC 中使用 JSONResult?

解决方案

ActionResult 是一个动作可以返回的抽象类.

Controller 中的辅助方法(例如,Json()Content()View(), ...) 返回不同的继承 ActionResult 的具体类,包括 JsonResult.

您应该将操作方法​​声明为返回 ActionResult,以便它们可以自由地返回任何具体的结果类.

I have 2 questions:

  1. What is the difference between JSONResult and ActionResult?

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆