From 16968a18d24a24a74ef871507deb5e643627b845 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Fri, 10 Sep 2021 13:43:12 -0700 Subject: [PATCH] Update action-return-types.md (#23271) --- aspnetcore/web-api/action-return-types.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/aspnetcore/web-api/action-return-types.md b/aspnetcore/web-api/action-return-types.md index a06809663c..6985639a87 100644 --- a/aspnetcore/web-api/action-return-types.md +++ b/aspnetcore/web-api/action-return-types.md @@ -1,7 +1,7 @@ --- title: Controller action return types in ASP.NET Core web API author: rick-anderson -description: Learn about using the various controller action method return types in an ASP.NET Core web API. +description: IActionResult vs IActionResult ms.author: scaddie ms.custom: mvc ms.date: 02/03/2020 @@ -139,9 +139,13 @@ For example, the following model indicates that requests must include the `Name` If the [`[ApiController]`](xref:Microsoft.AspNetCore.Mvc.ApiControllerAttribute) attribute in ASP.NET Core 2.1 or later is applied, model validation errors result in a 400 status code. For more information, see [Automatic HTTP 400 responses](xref:web-api/index#automatic-http-400-responses). -## ActionResult\ type +## ActionResult vs IActionResult -ASP.NET Core 2.1 introduced the [ActionResult\](xref:Microsoft.AspNetCore.Mvc.ActionResult`1) return type for web API controller actions. It enables you to return a type deriving from or return a [specific type](#specific-type). `ActionResult` offers the following benefits over the [IActionResult type](#iactionresult-type): +The following section compares `ActionResult` to `IActionResult` + +### ActionResult\ type + +ASP.NET Core includes [ActionResult\](xref:Microsoft.AspNetCore.Mvc.ActionResult`1) return type for web API controller actions. It enables you to return a type deriving from or return a [specific type](#specific-type). `ActionResult` offers the following benefits over the [IActionResult type](#iactionresult-type): * The [`[ProducesResponseType]`](xref:Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute) attribute's `Type` property can be excluded. For example, `[ProducesResponseType(200, Type = typeof(Product))]` is simplified to `[ProducesResponseType(200)]`. The action's expected return type is instead inferred from the `T` in `ActionResult`. * [Implicit cast operators](/dotnet/csharp/language-reference/keywords/implicit) support the conversion of both `T` and `ActionResult` to `ActionResult`. `T` converts to , which means `return new ObjectResult(T);` is simplified to `return T;`.