asp.net mvc: best proceed form checkboxes many-to-many db assoc list linq sql?
i have an asp.net mvc perspective contains checkboxes user-defined categories.
<td><% foreach (category c (list<category>)viewdata["cats"]) {
(selcats.containskey(c.id)) { %>
<input name="categoryids" type="checkbox" value="<%=c.id %>" checked="checked" /> <%= c.name%><% }
else { %>
<input name="categoryids" type="checkbox" value="<%=c.id %>" /> <%= c.name%> <% } %>
<% } %>
</td>
the form posted following controller action:
[acceptverbs(httpverbs.post)]
public actionresult edit(int id, int [] categoryids)
{
postsdatacontext db = new postsdatacontext();
var post = db.posts.single(p => p.id == id);
updatemodel(post, new[] { "title", "subtitle", "rawcontent", "publishdate", "slug" });
db.submitchanges();
relapse redirect("/archives/" + post.slug);
}
the form checkboxes converted an array integer ids "categoryids", any representing comparison category. i following wish put organization list containing twin columns: postid categoryid. used set adult many-to-many organization between posts categories.
currently i am brute-forcing it: looping by categories, any one, adding quarrel organization list containing problem id, id post belong.
but i'm wondering there's cleaner proceed automagically context asp.net mvc linq sql?
thanks!
Comments
Post a Comment