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
ASP.NET Core - Using TempData

ASP.NET Core - Using TempData

TempData is next to ViewBag and ViewData a common way to handle data for Requests and Views.

ViewData and ViewBag is only available in the current request and current View. TempData has the functionality to store data from one request to another. Keys inside TempData will be removed if you read them once!

Read Blog Post