i making partial view form form. in want display drop down using 3 values, :
<td> @html.dropdownlist("yes", "no", "not applicable") </td> obviously can not hard code values that, idea. i'll use drop down in view want keep logic here if possible, thing want keep track on selected value add hidden value id example. there way in view? thought passing viewbag argument or think there must more elegant solution this.
viewdata["mylist"] = new selectlist(new[] { "10", "15", "25", "50", "100", "1000" } .select(x => new {value = x, text = x}), "value", "text", "15"); then in view :
@html.dropdownlist("mylist") or can use linq generate select list
ilist<customer> customers = repository.getall<customer>(); ienumerable<selectlistitem> selectlist = c in customers select new selectlistitem { selected = (c.customerid == invoice.customerid), text = c.name, value = c.customerid.tostring() }; in case:
list<selectlistitem> ls = new list<selectlistitem>(); ls.add(new selectlistitem() { text = "yes", value = "true", selected = true }); ls.add(new selectlistitem() { text = "no", value = "false", selected = false }); ls.add(new selectlistitem() { text = "not applicable", value = "null", selected = false }); viewdata["mylist"] = ls;
Comments
Post a Comment