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

Creating explicit contracts with request objects

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

Start my 1-month free trial

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…

Contents