的ActionResult VS JSONresult [英] Actionresult vs JSONresult

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

问题描述

我有2个问题:


  

      
  1. 什么是JSONResult和ActionResult的区别?


  2.   
  3. 当在MVC中使用JSONResult?


  4.   


解决方案

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

控制器的辅助方法(例如, JSON()内容() 查看(),...)返回继承的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 VS JSONresult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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