差的ViewResult()和的ActionResult()之间 [英] Difference Between ViewResult() and ActionResult()

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

问题描述

是什么在ASP.NET MVC 的ViewResult()的ActionResult()之间的区别?

 公开的ViewResult指数()
{
    返回查看();
}公众的ActionResult指数()
{
    返回查看();
}


解决方案

的ActionResult是,可以有几种亚型的抽象类。

的ActionResult亚型


  • 的ViewResult - 渲染一个specifed以响应流


  • PartialViewResult - 渲染一个specifed局部视图响应流


  • EmptyResult - 返回一个空的响应


  • RedirectResult - 执行一个HTTP重定向到URL specifed


  • RedirectToRouteResult - 执行一个HTTP重定向到被确定的网址
    路由引擎,根据给定数据路由


  • JsonResult - 序列化一个给定的ViewData对象来JSON格式


  • JavaScriptResult - 返回一段JavaScript代码code,可以在客户端上执行


  • ContentResult类型 - 内容写入到响应流,而不需要一个视图


  • FileContentResult - 返回一个文件到客户端


  • FileStreamResult - 返回文件到客户端,这是由流提供


  • FilePathResult - 返回一个文件到客户端


资源

What is the difference between ViewResult() and ActionResult() in ASP.NET MVC?

public ViewResult Index()
{
    return View();
}

public ActionResult Index()
{
    return View();
}

解决方案

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

Resources

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

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