What are all the ASP.Net MVC Action Results?

吃可爱长大的小学妹 提交于 2019-12-03 10:38:49

If you open System.Web.Mvc using Reflector, you will see that there are several derived types that inherit from the abstract class ActionResult. They are:

System.Web.Mvc.ContentResult
System.Web.Mvc.EmptyResult
System.Web.Mvc.FileResult
    System.Web.Mvc.FileContentResult
    System.Web.Mvc.FilePathResult
    System.Web.Mvc.FileStreamResult
System.Web.Mvc.HttpUnauthorizedResult
System.Web.Mvc.JavaScriptResult
System.Web.Mvc.JsonResult
System.Web.Mvc.RedirectResult
System.Web.Mvc.RedirectToRouteResult
System.Web.Mvc.ViewResultBase
    System.Web.Mvc.PartialViewResult
    System.Web.Mvc.ViewResult

Yes, you can roll your own by inheriting from the abstract class ActionResult. You can study one or more of the ActionResults in the list above with Reflector to get a feel for how this would be done.

The source code is also available here:

http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471

If you're looking this up for ASP.NET MVC 5, add HttpStatusCodeResult to the list.

Also it's worth to mention that the helper methods that return the corresponding action result, do not have the word "Result" at the end. For example to return a HttpNotFoundResult, you will write return HttpNotFound("status description");.

ActionResult Class page on MSDN has the full list of result classes and the helper methods.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!