Sunday, January 18, 2015

ASP.NET MVC Basic Model Binding

ASP.NET MVC Basic Model Binding

View and its underlying model binding is a very important part of MVC. Here, I will show some of the basic steps which helps to understand basic binding concept.

Main terms that is involved in this scenario:
    -DTO/Model
    -View Model
    -Binding


DTO/Model:
Data transfer object (DTO) is one of the main component of OOP programming . Which is used fulfill different application scenario. We often require user input which relates to different DTO's.

MVC has great binding capability which we can use easily.


View Model:
This is a custom model only for view which actually hold the DTO reference and other parts that is required for view.


Controller:




















View code:


Output of the app:




























When user press Save:
It will submit to Person post action.
Here is the debugging output on Post method where action parameter is PersonViewModel with user input data:


Now we can use the binded view model for different business scenario of the app.

Download Source




No comments:

Post a Comment