ASP.NET MVC Model binding is one of the best features in ASP.NET MVC Framework. It is a bridge between HTTP request and action methods. It helps GET and POST to get automatically transferred into the data model.
MVC Model Binder uses Default Model Binder for building model parameter for MVC runtime.
Now, before this we would like to first explain simple model binding.
- Now, we have created a new MVC Web application project by File- New Project- Web Application – MVC.
- Now, we will add a new strongly typed View which we will bind to the model, as shown below.
- @model ModelBinding.Models.Client
- @ {
- ViewBag.Title = "GetClient";
- } < h3 Details < /h3>
- < h2 >
- Cleint Code: @Model.ClientCode
- < br / >
- Cleint Name: @Model.ClientName
- < /h2>
- Now, add a Client Model in Models folder, as shown below.
- public class Client {
- public string ClientCode {
- get;
- set;
- }
- public string ClientName {
- get;
- set;
- }
- }
- Add ClientController which is shown below.
- public class ClientController: Controller {
- // GET: Client
- public ActionResult GetClient() {
- Client cnt = new Client {
- ClientCode = "1001",
- ClientName = "Aman"
- };
- return View(cnt);
- }
- }
- Now, add another action method as EnterClient which will allow the users to enter client details, as shown below.
- public ActionResult EnterCleint() {
- return View();
- }
- As shown below, it is having two textboxes and Submit button. Along with it, the form is using POST method for the action Submit.
- @ {
- ViewBag.Title = "EnterCleint";
- } < h2 > EnterCleint < /h2> < form action = "Submit"
- method = "post" > Cleint Code: < input type = "text"
- name = "ClientCode " / > < br / > Cleint Name: < input type = "text"
- name = "ClientName " / > < br / > < input type = "submit"
- value = "Submit"
- id = "Submit" / > < /form>
- Now, we will create Submit action methond in the Controller.In the above code, we are fetching the values on the basis of textbox name and assigning it to Client and passing to GetCleint View.
- public ActionResult Submit() {
- Client cnt = new Client {
- ClientCode = Request.Form["CleintCode"],
- ClientName = Request.Form["CleintName"]
- };
- return View("GetClient", cnt);
- }
- Now, you can improve your code by adding parameter of type model in action method as shown below,
- public ActionResult Submit(Client cnt) {
- return View("GetClient", cnt);
- }

Join the conversation! Your thoughts help the community grow.