tags:

views:

470

answers:

4

I'm working on my first .NET MVC application and using the NerdDinner tutorial as a reference point. One point that is intriguing me at the moment is the UpdateModel() method. (I don't like using things I don't really understand.)

Taken from the NerdDinner tutorial -

//
// POST: /Dinners/Edit/2

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues) {

    Dinner dinner = dinnerRepository.GetDinner(id);

    UpdateModel(dinner);

    dinnerRepository.Save();

    return RedirectToAction("Details", new { id = dinner.DinnerID });
}

My main question is how does the UpdateModel() get access to the formValues passed in the Edit method? Why is the collection not passed in explicitly as a parameter to the method?

A: 

It probably just gets it from the Request.Form alias.

User
+3  A: 

You can see how it works directly from the source code.

Mauricio Scheffer
A: 

I would get the ASP.NET MVC source from Microsoft, and use that to step through your code. You will then be able to see exactly what magic they are doing :-)

mc2thaH
A: 

It does inspect all the HttpRequest inputs such as Form, QueryString, Cookies and Server variables. I think in this order.

Andrei Rinea