Merge pull request #7802 from aspnet/scottaddie/model-state-patch
Replace line numbers range with snippet namepull/7803/head
commit
95407f8f26
|
@ -47,10 +47,12 @@ namespace WebApiSample.Api.Controllers
|
||||||
[ProducesResponseType(400)]
|
[ProducesResponseType(400)]
|
||||||
public async Task<IActionResult> CreateAsync([FromBody] Pet pet)
|
public async Task<IActionResult> CreateAsync([FromBody] Pet pet)
|
||||||
{
|
{
|
||||||
|
#region snippet_ModelStateIsValidCheck
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
await _repository.AddPetAsync(pet);
|
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:
|
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);`:
|
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