我的模型中有两个DropDownList元素。
[DisplayName("Site")]
public List<KeyValuePair<int, string>> Site { get; set; }
public int SelectedSiteID { get; set; }
<%= Html.DropDownListFor(model => model.SelectedSiteID, new SelectList(Model.Site, "Key", "Value"))%>
[DisplayName("Data Center")]
public List<KeyValuePair<int, string>> DataCenter { get; set; }
public int SelectedDataCenterID { get; set; }
<%= Html.DropDownListFor(model => model.SelectedDataCenterID, new SelectList(Model.DataCenter, "Key", "Value"))%>当用户更改第一个选择时,我试图在第二个DropDownList中修改ListItem的集合。
我认为这是有可能的,但我想确认这是一个良好的做法:
这一切似乎有点..。非MVC3y,如果你愿意的话。这是实现我所要求的目标的标准方式,还是有更明确的方法?
发布于 2012-10-31 20:07:31
我认为最好在这个场景中使用Jquery。
最好的方法是将firstDropdown框绑定到Jquery中的OnChange事件,然后使用$.ajax在Controller中加载来自JSONresult的数据。一旦加载了该数据,就会在secondDropdown中加载数据。
如果您需要代码帮助,请告诉我。
发布于 2012-10-31 20:13:38
我使用jQuery级联选择插件为我做到这一点。这是很容易插入,不需要你重新发明车轮。http://code.google.com/p/jquery-cascade/
https://stackoverflow.com/questions/13166253
复制相似问题