MVC3 ViewResult vs ActionResult [英] MVC3 ViewResult vs ActionResult

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

问题描述

我想知道ViewResult和ActionResult之间的区别



以下两种操作方法的区别是什么?如何决定何时使用ViewResult或ActionResult

I want to know the difference between ViewResult and ActionResult

What will be the difference of below two action methods? and how can one decide when to use ViewResult or ActionResult

public ActionResult Index()
       {

           return View();
       }

public ViewResult Index()
       {

           return View();
       }

推荐答案

ActionResult - 是一个抽象类,可以有几种子类型:



ViewResult - 为响应流呈现指定的视图
ActionResult -is an abstract class that can have several subtypes:

ViewResult - Renders a specifed view to the response stream


ActionResult是一个抽象类,可以有多个子类型。



ActionResult子类型



ViewResult - 为响应流呈现指定的视图



PartialViewResult - 向响应流渲染指定的局部视图



EmptyResult - 返回空响应



RedirectResult - 执行HTTP重定向到指定的URL



RedirectToRouteResult - 根据给定的路由数据执行HTTP重定向到由路由引擎确定的URL



JsonResult - 将给定的ViewData对象序列化为JSON格式



JavaScriptResult - 返回一块Jav可以在客户端执行的aScript代码



ContentResult - 将内容写入响应流而无需查看



FileContentResult - 将文件返回给客户端



FileStreamResult - 将文件返回给客户端,由Stream提供



FilePathResult - 将文件返回给客户端
ActionResult is an abstract class that can have several subtypes.

ActionResult Subtypes

ViewResult - Renders a specifed view to the response stream

PartialViewResult - Renders a specifed partial view to the response stream

EmptyResult - An empty response is returned

RedirectResult - Performs an HTTP redirection to a specifed URL

RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data

JsonResult - Serializes a given ViewData object to JSON format

JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client

ContentResult - Writes content to the response stream without requiring a view

FileContentResult - Returns a file to the client

FileStreamResult - Returns a file to the client, which is provided by a Stream

FilePathResult - Returns a file to the client


Google将告诉你 [ ^ ]



以下是Google提供的一些惊人结果:



Viewresult()和ActionResult()之间的差异[ ^ ]

ViewResult vs ActionResult - asp.net MVC [ ^ ]
Google will tell you[^]

Here are some of the amazing results provided by Google:

Differnce Between Viewresult() and ActionResult()[^]
ViewResult vs ActionResult - asp.net MVC[^]


这篇关于MVC3 ViewResult vs ActionResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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