【发布时间】:2009-04-01 13:43:25
【问题描述】:
我目前正在学习 ASP.NET MVC 并使用 Nhibernate。
我想使用级联下拉框。有没有人设法让级联下拉框在 MVC 中工作?
更新: 我查看了以下网站:link text 并使用了方法 1。
控制器代码
var makeList = new SelectList(makeRepository.ListMakes (), "Id", "make",1);
ViewData["Makes"] = makeList;
//// Create Models view data
var modelList = new CascadingSelectList(modelRepository.ListModels (Convert.ToInt32(makeList.SelectedValue.ToString())), "ModelID","Id", "Name");
ViewData["Models"] = modelList;
查看代码
<%= Html.DropDownList("--Select Make--","Makes")%>
<label for="Makes">Car Model:</label>
<%= Html.CascadingDropDownList("Models", "Makes") %>
The correct list of cars is listed when a Make with id of 1 is selected, but when I select a different make the model list is empty?
【问题讨论】:
-
您的模型列表应该包含所有模型。现在您只为选定的(第一个)品牌选择模型。
标签: asp.net-mvc cascadingdropdown