If you are trying to bind to multiple models on postback, you should try using the Bind attribute and specifying the prefixes used for each model in your arguments. In some scenarios -- where you may not be able to use separate prefixes for your model elements -- you might find this easier to do with multiple TryUpdateModel and separate whitelists rather than putting the models in the parameters.
public ActionResult Update( [Bind(Prefix="Customer")]Customer customer,
[Bind(Prefix="Address")]Address address )
{
...
}
This would assume you have a ViewModel like:
public class CustomerAddressModel
{
public Customer Customer { get; set; }
public Address Address { get; set; }
}
and reference it like:
<%= Html.TextBox( "Customer.Name" ) %>
...
<%= Html.TextBox( "Address.Street" ) %>
or, using TryUpdateModel,
public ActionResult Update( int id )
{
var customer = db.Customers.Where( c => c.ID == id ).Single();
var whitelist = new string[] { "name", "company", ... };
if (TryUpdateModel( customer, whitelist ))
{
var addressWhitelist = new string[] { "street", "city", ... };
if (TryUpdateModel( customer.Address, addressWhitelist ))
{
...
}
}
}
In this case, your model might contain just the fields from the two different models that you are trying to update.
public class CustomerAddressModel
{
public string Name { get; set; }
public string Company { get; set; }
public string Street { get; set; }
...
}