简体   繁体   English

ActionResult 类之间的区别

[英]Difference between ActionResult classes

What is the difference between Microsoft.AspNetCore.Mvc.ActionResult and System.Web.Mvc.ActionResult? Microsoft.AspNetCore.Mvc.ActionResult 和 System.Web.Mvc.ActionResult 有什么区别?

When should you use one or the other one?什么时候应该使用其中一种或另一种?

Microsoft.AspNetCore.Mvc.ActionResult Microsoft.AspNetCore.Mvc.ActionResult

as it is showing, it is applied in asp.net core.如图所示,它应用于 asp.net 内核。 this executes the result operation method asynchronusly.这将异步执行结果操作方法。 it is the default implementation of IActionResult.它是 IActionResult 的默认实现。

System.Web.Mvc.ActionResult It is applied to ASP.NET MVC. System.Web.Mvc.ActionResult适用于 ASP.NET MVC。 it simply represents the result of an action method.它只是表示一个动作方法的结果。 It performs the operation synchronously.它同步执行操作。

The System.Web.Mvc namespace is used the .NET Framework. System.Web.Mvc命名空间用于 .NET 框架。 If your project is targetting the .NET Framework, use System.Web.Mvc.ActionResult .如果您的项目针对 .NET 框架,请使用System.Web.Mvc.ActionResult

Below list is all return type from System.Web.Mvc.ActionResult :下面的列表是来自System.Web.Mvc.ActionResult的所有返回类型:

  • ViewResult : Represents HTML and markup. ViewResult :表示 HTML 和标记。
  • EmptyResult : Represents no result. EmptyResult :表示没有结果。
  • RedirectResult : Represents a redirection to a new URL. RedirectResult :表示重定向到新的 URL。
  • JsonResult : Represents a JavaScript Object Notation result that can be used in an AJAX application. JsonResult :表示 JavaScript Object 表示结果,可用于 AJAX 应用程序。
  • JavaScriptResult : Represents a JavaScript script. JavaScriptResult :表示 JavaScript 脚本。
  • ContentResult : Represents a plain text result. ContentResult :表示纯文本结果。
  • FileContentResult : Represents a downloadable file (with the binary content). FileContentResult :表示可下载的文件(带有二进制内容)。
  • FilePathResult : Represents a downloadable file (with a path). FilePathResult :表示可下载的文件(带有路径)。
  • FileStreamResult : Represents a downloadable file (with a file stream). FileStreamResult :表示可下载的文件(带有文件流)。

The Microsoft.AspNetCore.Mvc namespace is used in .NET Core. Microsoft.AspNetCore.Mvc命名空间用于 .NET 核心。 If your project is targetting .NET Core, use Microsoft.AspNetCore.Mvc.ActionResult .如果您的项目针对 .NET 核心,请使用Microsoft.AspNetCore.Mvc.ActionResult

ASP.NET Core offers the following options for web API controller action return types: ASP.NET 内核为 web API Z594C103F2C6E04C3D18AB059F031E0 类型提供以下选项返回:C

  • Specific type
  • IActionResult
  • ActionResult<T>

List of common return types in Microsoft.AspNetCore.Mvc.ActionResult : Microsoft.AspNetCore.Mvc.ActionResult中的常见返回类型列表:

  • ViewResult : Represents HTML and markup. ViewResult :表示 HTML 和标记。

  • ContentResult : Represents content like plain text, XML, html. ContentResult :表示纯文本等内容,XML,html。

  • JsonResult : Represents a JavaScript Object Notation result that can be used in an AJAX application. JsonResult :表示 JavaScript Object 表示结果,可用于 AJAX 应用程序。

  • PartialViewResult : Represents PartialView. PartialViewResult :表示 PartialView。

  • RedirectResult : Represents a redirection to a new URL. RedirectResult :表示重定向到新的 URL。

  • RedirectToActionResult : Represents a redirection to specified action and controller. RedirectToActionResult :表示重定向到指定的操作和 controller。

  • RedirectToPageResult : Represents a redirection to a specified pageName (It is mostly used in Razor pages). RedirectToPageResult :表示重定向到指定的pageName(主要用于Razor页面)。

  • RedirectToRouteResult : Represents a route to redirect from one controller to another controller in cases we have more than one route. RedirectToRouteResult :如果我们有多个路由,则表示从一个 controller 重定向到另一个 controller 的路由。

  • StatusCodeResult : Represents an HTTP status code. StatusCodeResult :表示 HTTP 状态代码。

  • ViewComponentResult : Represents a "ViewComponent". ViewComponentResult :表示“ViewComponent”。

  • ChallengeResult : on execution invokes HttpContext.ChallengeAsync . ChallengeResult :在执行时调用HttpContext.ChallengeAsync

  • SignInResult : on execution invokes HttpContext.SignInAsync SignInResult :在执行时调用HttpContext.SignInAsync

  • SignOutResult : on execution invokes HttpContext.SignOutAsync . SignOutResult :在执行时调用HttpContext.SignOutAsync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM