问题描述
目前,我正在学习ASP.NET MVC和使用NHibernate。
I'm currently learning ASP.NET MVC and using Nhibernate.
我想使用级联下拉框。有没有人设法级联下拉框在MVC工作?
I would like to use Cascading Drop-Down Boxes. Has anyone managed to get cascading drop-down boxes working in MVC?
更新:
我已经看过以下网站:link文字以及使用的方法1。
Updated:I have looked at the following website: link text and used method 1.
控制器code
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;
查看code
<%= Html.DropDownList("--Select Make--","Makes")%>
<label for="Makes">Car Model:</label>
<%= Html.CascadingDropDownList("Models", "Makes") %>
上市汽车的正确列表当选择与1 ID的牌子,但是当我选择一个不同的模型使得列表是空的?
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?
推荐答案
您可能需要阅读本 TIP 。
在这篇文章中,斯蒂芬·沃尔特演示创建级联下拉列表的三种方法。首先,他展示了如何改变一个下拉列表中显示的选项列表时,在另一个下拉列表变更的选项。其次,他展示了如何通过一个控制器动作暴露的下拉列表中的数据。接下来,他展示了如何从Web服务抢的下拉列表中的数据。
In this tip, Stephen Walter demonstrates three methods of creating cascading dropdown lists. First, he shows you how to alter the list of options displayed by one dropdown list when an option in another dropdown list changes. Second, he shows you how to expose the data for the dropdown lists through a controller action. Next, he shows you how to grab the data for the dropdown lists from web services.
这篇关于ASP.NET MVC - 级联下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!