tags:

views:

118

answers:

1

Why would I use UpdateModel here?

A.

 public ActionResult SubmitPerson(Person person)
 {       }

B.

 public ActionResult SubmitPerson(FormCollection form)
{
    Person person=new Person();
    UpdateModel<IFilter>(person,form)
}
+2  A: 

It ultimately depends on your implementation requirements.

In A., a new instance of a Person object will be created and the model binder will attempt update the properties from the form.

In B., the example you have provided will also create a new Person object and will attempt to update the properties via the IFilter interface, which is one of the ways to specify a whitelist in MVC.

Another reason you might use option B is to updated an existing object (for example one that was populated from data in a database) instead of creating a new object instance.