F
funka420
Well, shortly after I posted my reply, I seem to have found a
workaround that is working in my situation. In my case, I have a
Company entity that has one to many relationship to Contacts (my Linq-
to-Sql EntitySet).
Since it seems that when I change my code from EntitySet<Contact> to
List<Contact>, the MVC default model binder starts working as expected
(even though the LTS isn't now), I figured I would provide an
alternate, "aliased" property to MVC that is of type List<Contact>,
and sure enough, this seems to work.
In my Company entity class:
// This is what LINQ-to-SQL will use:
private EntitySet<Contact> _Contacts = new EntitySet<Contact>();
[Association(Storage="_Contacts", OtherKey="CompanyID", ThisKey="ID")]
public EntitySet<Contact> Contacts
{
get { return _Contacts; }
set { _Contacts.Assign(value); }
}
// This is what MVC default model binder (and my View) will use:
public List<Contact> MvcContacts
{
get { return _Contacts.ToList<Contact>(); }
set { _Contacts.AddRange(value); }
}
So now, in my View, I have the following:
<label>First Name*
<%= Html.TextBox("Company.MvcContacts[" + i + "].FirstName") %>
</label>
<label>Last Name*
<%= Html.TextBox("Company.MvcContacts[" + i + "].LastName") %>
</label>
Seems to work like a charm!
Best of luck!
-Mike
workaround that is working in my situation. In my case, I have a
Company entity that has one to many relationship to Contacts (my Linq-
to-Sql EntitySet).
Since it seems that when I change my code from EntitySet<Contact> to
List<Contact>, the MVC default model binder starts working as expected
(even though the LTS isn't now), I figured I would provide an
alternate, "aliased" property to MVC that is of type List<Contact>,
and sure enough, this seems to work.
In my Company entity class:
// This is what LINQ-to-SQL will use:
private EntitySet<Contact> _Contacts = new EntitySet<Contact>();
[Association(Storage="_Contacts", OtherKey="CompanyID", ThisKey="ID")]
public EntitySet<Contact> Contacts
{
get { return _Contacts; }
set { _Contacts.Assign(value); }
}
// This is what MVC default model binder (and my View) will use:
public List<Contact> MvcContacts
{
get { return _Contacts.ToList<Contact>(); }
set { _Contacts.AddRange(value); }
}
So now, in my View, I have the following:
<label>First Name*
<%= Html.TextBox("Company.MvcContacts[" + i + "].FirstName") %>
</label>
<label>Last Name*
<%= Html.TextBox("Company.MvcContacts[" + i + "].LastName") %>
</label>
Seems to work like a charm!
Best of luck!
-Mike