tags:

views:

36

answers:

1

Hi All,

I'm using

UpdateModel(<model>, new[] {"Customer.Name", "FirstName", "etc..." })

Customer.Name is an property of Customer object which resides in a view model.

When I post the form I'm seeing that values are being posted as expected. When I get to the UpdateModel part the FirstName value is there but Customer.Name is not.

Any ideas? Additional note: if i take the inclusion off the UpdateModel and just say UpdateModel(model) it all works.

Thanks,

rod.

+1  A: 

Hey, If I understand your question correctly may be this example will be of some help:

Let's say the model is;

public class Customer{
 public string Name;
 public string Phone;
 public string Email;
}

The UpdateModel has the following signature :

UpdateModel(ModelInstance, string[] whiteList)

where the instance is your instance of the model and the whiteList is which properties to be updated on the model with the values posted to the controller action.

So if you, for example, have the following piece of code:

UpdateMode(myCustomerInstance, new string[] {"Name", "Phone"})

This will update the myCustomerInstance object with the posted values of Name and Phone, ignoring the posted Email value. So, for every property post-ed to the controller action it will use reflection to check if the model that is being updated contains a property with such a name. If it does, this property will be updated with the post-ed value.

It might be also helpful to take a look at TryUpdateModel as it will swallow any exceptions and just return bool indicating whether the operation was successful

Hope that clarifies what is going on a bit.

sTodorov