asp.net - HTML.DropDownList values from multiple sources? -
in asp.net mvc, possible fill list of values of html.dropdownlist multiple data sources along multiple manually entered values?
basically, envision being formated below using along lines of optgroup:
**group 1** manual item 1 manual item 2 **group 2** ds1 item 1 ds1 item 2 **group 3** ds2 item 1 ds2 item 2
i've thought using view on db , getting data that, however, i've not faintest how lay out above using helpers , pass data multiple sources.
thanks in advance.
as start model (actually start unit test no time here):
public class mymodel { public string selecteditem { get; set; } public ienumerable<selectlistitem> items { get; set; } }
then controller:
public class homecontroller : controller { public actionresult index() { var items1 = new[] { new { value = "1", text = "manual item 1" }, new { value = "2", text = "manual item 2" }, }; // todo: go fetch repo1 var items2 = new[] { new { value = "3", text = "ds1 item 1" }, new { value = "4", text = "ds1 item 2" }, }; // todo: go fetch repo2 var items3 = new[] { new { value = "5", text = "ds2 item 1" }, new { value = "6", text = "ds2 item 2" }, }; var items = items1.concat(items2).concat(items3); var model = new mymodel { items = new selectlist(items, "value", "text") }; return view(model); } }
and typed view model:
<%@ page language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<myapp.models.mymodel>" %> <asp:content id="content2" contentplaceholderid="maincontent" runat="server"> <%= html.dropdownlistfor(x => x.selecteditem, model.items) %> </asp:content>
you define intermediary type avoid anonymous types i've used brevity.
remark: if original question using optgroup ignore answer , make intention clear can more adapted answer.
Comments
Post a Comment