I am wondering how to use Model Binding in a scenario where I am returning information from more than one entity on a page?
I want to display a combination of fields from two separate entities, ie Customer + Address. I am using Microsoft’s DAAB and custom business entities for my model.
Any ideas?
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.
This would assume you have a ViewModel like:
and reference it like:
or, using TryUpdateModel,
}
In this case, your model might contain just the fields from the two different models that you are trying to update.