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.