From the course: ASP.NET MVC: Building for Productivity and Maintainability

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Creating a model validation action filter

Solution: Creating a model validation action filter

From the course: ASP.NET MVC: Building for Productivity and Maintainability

Start my 1-month free trial

Solution: Creating a model validation action filter

(gentle music) - [Narrator] In this challenge, I asked you to move these three all too common lines of code into a Custom Action Filter, so that they can be removed from each individual controller action looking to ensure the model is valid prior to processing the request. In order to solve this challenge, you had to do almost exactly what I showed you in the Custom Action Filter video. That means that you had to do three things. Create a Custom Action Filter Attribute class, override the OnExecuting method on that Action Filter base class, and then adorn the controller actions that need model validation and remove those three Model Validation lines that I showed earlier. Note that I just said the OnActionExecuting method. This is a crucial part of the solution, since this method gets executed before the Controller Action Logic. You needed to choose this method because the Model Validation Logic that you're looking to replace, comes at the beginning of the controller action. Now, I'll…

Contents