c# - Multiple model binding to list of object in asp.net mvc -
can tell me how select multiple rows many different id in table , store viewbag?
this line can rows id "123": viewbag.name = (from m in mydatabase.mytable m.id == "123" select m).tolist();
calling in view:
<tr> foreach(var item in viewbag.name) { <td>@item.productname</td> <td>@item.category</td> } </tr>
now. have list store values of id. this:
list<string> list = new list<string>(); list.add("123"); list.add("456"); list.add("789"); //.....
and un-complete loop:
foreach(var item in list) { // viewbag.name = m in mydatabase.mytable .......... }
please help!
replace list
hashset
(small optimization):
hashset<string> list = new hashset<string>(); list.add("123"); list.add("456"); list.add("789"); // ...
query:
viewbag.name = (from m in mydatabase.mytable list.contains(m.id) select m).tolist();
add model view, , put result in model, not in viewbag
.
Comments
Post a Comment