This article describes various ways of model binding possible in MVC that has a magical power.
This article describes various ways of model binding possible in MVC that has a magical power. This article is intended for the audience having at least a basic knowledge of request flow in MVC.ASP.NET MVC model binding allows you to map and bind HTTP request data with a model. This is done automatically by MVC Model Binder. The mapping of the request with the model is done by comparison with the name attribute of controls.
Suppose I am considering as an example the saving of a magazine article. The following is my Action Method that returns a View.Once I request for action method: http://localhost:64640/Articles/SaveArticle
The ValueProviderDictionary pulls out the values from the HTTP request and stores them as strings. The fetching is done in the following order:
Once this data is fetched from the HTTP request, the DefaultModelBinder class takes the responsibility of converting this string object to actual .Net object. This class implements an IModelBinder interface.Let's consider each way to do model binding.
Use the following procedure to create a Custom Binder.
Conclusion
This is how strongly the Model Binder is and helps to bind the request with the model. The builtin model binding capabilities automatically takes care of primitive types, class types and collections. I hope you liked this article. Please share your comments, it is valuable to me and keep sharing no matter what ;)
Reference
ASP.NET MVC 5: A Beginner’s Guide