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
From the course: ASP.NET MVC: Building for Productivity and Maintainability
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Reducing duplicate code with custom action filters5m 49s
-
(Locked)
Creating explicit contracts with request objects6m 51s
-
(Locked)
Moving business logic from a controller to a service7m 10s
-
(Locked)
Consuming a service from a controller3m 11s
-
(Locked)
Challenge: Creating a model validation action filter2m 7s
-
(Locked)
Solution: Creating a model validation action filter3m 55s
-
(Locked)
-
-
-