Replace line numbers range with snippet name

pull/7802/head
Scott Addie 2018-07-24 21:44:05 -05:00
parent 40955562d1
commit 4b4b8e5f2a
2 changed files with 3 additions and 1 deletions

View File

@ -47,10 +47,12 @@ namespace WebApiSample.Api.Controllers
[ProducesResponseType(400)]
public async Task<IActionResult> CreateAsync([FromBody] Pet pet)
{
#region snippet_ModelStateIsValidCheck
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
#endregion
await _repository.AddPetAsync(pet);

View File

@ -57,7 +57,7 @@ The following sections describe convenience features added by the attribute.
Validation errors automatically trigger an HTTP 400 response. The following code becomes unnecessary in your actions:
[!code-csharp[](../web-api/define-controller/samples/WebApiSample.Api.Pre21/Controllers/PetsController.cs?range=46-49)]
[!code-csharp[](../web-api/define-controller/samples/WebApiSample.Api.Pre21/Controllers/PetsController.cs?name=snippet_ModelStateIsValidCheck)]
The default behavior is disabled when the [SuppressModelStateInvalidFilter](/dotnet/api/microsoft.aspnetcore.mvc.apibehavioroptions.suppressmodelstateinvalidfilter) property is set to `true`. Add the following code in *Startup.ConfigureServices* after `services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);`: