From the course: ASP.NET MVC: Building for Productivity and Maintainability
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Creating explicit contracts with request objects
From the course: ASP.NET MVC: Building for Productivity and Maintainability
Creating explicit contracts with request objects
- [Instructor] One of the best features of the ASP.Net MVC framework is model binding, the ability to simply define a parameter on a controller action and have the framework automatically populate that object from the request. And to demonstrate it, just about every tutorial, including my own, will tell you to write code like I'm showing here on line 40, model binding directly to a model class that's stored in the database. The reason that tutorials will tell you to do this is because it's incredibly simple and straightforward. And for many applications, this may actually be the best way to write the application. But when you consider the impacts of this approach, the drawbacks start to become evident. In fact, you don't even need to go past this line. This bind attribute exists only to exclude the ID property from model binding because we don't want users to be able to define their own entity IDs, possibly allowing them to overwrite existing objects as opposed to creating a new one…
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
-
-
-
-
-
-
-
Reducing duplicate code with custom action filters5m 49s
-
Creating explicit contracts with request objects6m 51s
-
Moving business logic from a controller to a service7m 10s
-
Consuming a service from a controller3m 11s
-
Challenge: Creating a model validation action filter2m 7s
-
Solution: Creating a model validation action filter3m 55s
-
-
-
-