Chapter 4. The Model

Throughout the first few chapters of this book you became familiar with basic Model-View-Controller (MVC) principles, how working with ASP.NET MVC differs from working with ASP.NET WebForms, and the general workings of ASP.NET MVC. Here in Chapter 4 your in-depth examination of the ASP.NET MVC begins with a discussion of the first element in the Model-View-Controller pattern: the model.

Any implementation of software in the MVC pattern consists of three main components, and the first element is the model. The model is the component responsible for encapsulating the data layer manipulations of your application in a simple API that can be used in the controller component easily and quickly. Moreover, it's responsible for including your business logic for what's going to happen with your data. This not only helps to reduce the coupling between your components but also improves the readability of your code significantly.

There is no one specific way to build your models, especially in ASP.NET MVC where a wide range of options exist for building your data storage infrastructure. You have various options for implementing your model component, including traditional data interactions with relational databases, different Object Relational (O/R) Mappers, and programming components for working with other data storage types such as XML or even text files. This gives you the flexibility to work in a variety of ways, and you can choose whatever way is most comfortable for you ...

Get Beginning ASP.NET MVC 1.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.