Book Image

ASP.NET Core 2 Fundamentals

By : Onur Gumus, Mugilan T. S. Ragupathi
Book Image

ASP.NET Core 2 Fundamentals

By: Onur Gumus, Mugilan T. S. Ragupathi

Overview of this book

The book sets the stage with an introduction to web applications and helps you build an understanding of the tried-and-true MVC architecture. You learn all about views, from what is the Razor view engine to tagging helpers. You gain insight into what models are, how to bind them, and how to migrate database using the correct model. As you get comfortable with the world of ASP.NET, you learn about validation and routing. You also learn the advanced concepts, such as designing Rest Buy (a RESTful shopping cart application), creating entities for it, and creating EF context and migrations. By the time you are done reading the book, you will be able to optimally use ASP.NET to develop, unit test, and deploy applications like a pro.
Table of Contents (14 chapters)

Model Binding


Model binding is the process of mapping the model data coming from the view to the ViewModel parameter of the action method in the controller.

Model binding eliminates the need to read the form data manually and assign it to the existing object. This would have been very tedious and error-prone. Model binding can also be enhanced and customized. It is a powerful mechanism to parse the incoming request automatically.

Let us consider a simple form with a couple of form fields: Name and EmailID. On submission of the form, these values would be mapped to the ViewModel object of the action method of the controller. Model binding takes care of this mapping. The model binder looks for a match in the form fields, query strings, and request parameters.

In the preceding example, any class with these properties would be picked up by ModelBinder without any issues.

As the following Person class contains the Name and EmailID properties, the model binder would not complain about using this model...