In an MVC3 Razor application using EF4 I have a problem.
EF4 generates POCO classes and adds navigation properties for nested collections. A navigation property is always of type ICollection<T>
.
In a View I try to bind to a class which has such a navigation property;
@Html.TextBoxFor(m => m.Items[0].Quantity)
This would generate a correctly named input field "Model.Items[0].Quantity". But because the property is ICollection<T>
, I cannot use indexers. So I try:
@Html.TextBoxFor(m => m.Items.First().Quantity)
But that will generate an incorrect input field with the id "Quantity", and the DefaultModelBinder will not be able to bind correctly.
So, how can I bind a Model with a nested ICollection property?