Blog Posts with tag "ASP:NET Core"

ASP.NET Core ModelState Validation Filter

ASP.NET Core ModelState Validation Filter

During my code review sessions I see a lot of duplicate for the ModelState validation like

1public async Task<IActionResult> AddAsync(PersonAddSubmitModel model)
2{
3    if(ModelState.IsValid)
4    {
5        return BadRequest(ModelState);
6    }
7
8    // ......
9}

But it makes no sense to use the same code in every action to validate your submit model. It can be easier!

Read Blog Post