This article explains how to bind multiple models from a view. Sometimes the scenario may exist like this; we need to populate more than one model with the user's input. Let's implement this in a small example.
First, we will look at our model classes. Here is a small sample. The classes are fragmented within various namespaces. Anyway, we would like to bind all the classes from a single view. I have kept the ABC class within various namespaces purposefully. Just to show that it's not necessary to have all model classes within the same namespace and how strong MVC is in mapping. Haha.
Here is our view that will get the user's data as input. We have used an aspx view and HTML helper class to create HTML elements. If we look closely at the HTML form then we will find that we have kept the text box name the same as the property name of the class. Please keep the same name otherwise it will not bind the value, yet you will not see an error.
Fine, we are nearly done with our settings. We will now create a controller to receive the form submission event. In the person controller, we have defined two actions, the first action (Index) will return the view and when we click on the submit button, it will hit the save data action.
Once we run the application and set a breakpoint on saved data, we will find that all model parameters are populated with a value.
![Run the application]()
We have expanded the value of the p model but we will get all populated objects here.
Conclusion
In this example, we learned how to bind data to multiple models from a single view. I hope this concept will help you in your day-to-day project development life.