0

It's been bothering me for sometimes. I can see plenty of examples where actions read data from a View (data sent by POST) in many different ways. Specially in this topic on handling multiple submit buttons, for instance:

the model is read from a view:

public ActionResult Edit(Model model)
{
}

or only ID and then TryUpdateModel somehow knows which to update

public ActionResult Edit(int? PropertyID)
{
    //...
    Model modelToEdit = dbContext.Objects.Find(PropertyID);
    if(TryUpdateModel(modelToEdit)
    {
    }
}

Sometimes programmers read strings from submit buttons I guess:

public ActionResult Edit(string button1, string button2 /*, ... */)
{
}

or both strings and models are received in a controller

public ActionResult Edit(string button1, Model model)
{
}

How controllers "know" that that ID is the ID one has to use etc. I would be grateful if someone could explain what exactly happens between View and controller. It's like the model is sent for us and it's up to us how we are going to receive it!
Another question would be on why some programmers read only IDs whereas the others read the whole objects etc.

Community
  • 1
  • 1
Celdor
  • 2,437
  • 2
  • 23
  • 44
  • 3
    Take a look at how the DefaultModelBinder works (http://odetocode.com/blogs/scott/archive/2009/04/27/6-tips-for-asp-net-mvc-model-binding.aspx) – Andy T Nov 25 '14 at 18:58
  • @QuetiM.Porta Thanks for the link. I read it and withing the text I have found [another link to a great post](http://www.codethinked.com/ASPNET-MVC-Think-Before-You-Bind) that explains most of what confuses me here :). Cheers! – Celdor Nov 25 '14 at 19:47

0 Answers0