Typically, the Binder Model (in MVC) looks at your action method and sees what it needs (such as object types). He then tries to find the values from the HTTP request (values in the HTTP form, QueryString, Json, and possibly in other places, such as cookies, etc., Using ValueProviders). Then it creates a new object with the parameters that it retrieves.
IMO What you did is not really a "model binding". In the sense that you just read the identifier and retrieved the object from the database.
An example of a normal model binding:
// class public class SomeClass { public int PropA {get;set;} public string PropB {get;set;} } // action public ActionResult AddSomeClass(SomeClass classToBind) { // implementation } // pseudo html <form action=""> <input name="PropA" type="text" /> <input name="PropB" type="text" /> </form>
if you publish a form containing the correct values (say you submit the form with PropA and PropB), the model’s middleware can determine that you submitted these values on the form and created the SomeClass object.
If you really want to create a real working example, you should use a strongly typed View and use the HtmlHelper EditorFor (or EditorForModel) to create all the correct names that MVC needs.
-
for the MVC link, the default is DefaultModelBinder , and some (moreover, you can look in System.Web. Mvc). The defaultProviders that it uses are FormValueProvider and QueryStringValueProvider
So, as I said, how it works in the main is that by default the connecting device reads the model that the action receives (for example, SomeClass in the example), reads what values they can read (for example, PropA and PropB) and queries ValueProviders for the correct property values.
Also, if I remember correctly, you can also see the value providers at runtime using the static ValueProviderFactories class.