ASP.NET MVC and LINQ to SQL: linking table, checkboxes
I am very new to MVC and from what I learned, I can have a form (a View) linked to a Model.
Now I have a View for adding a new Client, so the View inherits from Client.
I have something like this for each field <%= Html.LabelFor(model => model.FirstName) %>
<%= Html.TextBoxFor(model => model.FirstName)%>
<%= Html.ValidationMessageFor(model => model.FirstName)%>
No problem with that, it can be saved to the database without any SQL statements thanks to LINQ.
Now the problem is, a Client can belong to Group(s)
(the relation between Clients and Groups is many to many)I have created a linking开发者_运维技巧 table called ClientGroups that has 2 columns:
ClientID GroupIDIdeally the form should have a checkbox list, so I am wondering if something similar to this can be done
<label>Groups</label>
<%= Html.CheckBoxListFor(model => model.Groups)%>
That won't compile, but what is the proper way of doing it?
Thanks in advance!
i'd create GroupViewModel and use it instead of Group; GroupViewModel should contain something like NamedValueCollection with entities - then you should be able to use it in HtmlHelpers
精彩评论