I have an ASP.NET MVC view which contains checkboxes for user-defined categories.
<% foreach (Category c in (List)ViewData[\"cats\"]
-
I think what you're doing is fine... the only thing I would say is that if you don't want to loop through the ID's, you could add them at the same time with "InsertAllOnSubmit" (even though this is really just looping too):
int[] categoryIDs = new int[] { 0, 1, 2 };
dataContext.PostCategories.InsertAllOnSubmit(
categoryIDs.Select(id =>
new PostCategory
{
CategoryID = id,
PostID = myPostID
})
);
But either way, that's still just doing the same as what you have.
讨论(0)
- 热议问题