Replace line numbers range with snippet name
parent
40955562d1
commit
4b4b8e5f2a
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);`:
|
||||
|
||||
|
|
Loading…
Reference in New Issue