【发布时间】:2016-09-01 07:52:48
【问题描述】:
我在页面上使用级联下拉菜单。第一个下拉列表是从 ViewBag 中填充的
@Html.DropDownList("OrgGroupID",
(IEnumerable<SelectListItem>)ViewBag.OrgGroups,
new Dictionary<string, object>
{
{ "class", "form-control" },
{ "width", "100%" },
{ "data-placeholder", "Select Group..." },
{ "onchange", "groupSelected(this)" }
})
当从第一个值中选择一个值时,第二个值被填充。第二个下拉菜单的标记是
@Html.ListBox("Devices",
(IEnumerable<SelectListItem>)ViewBag.Devices,
new Dictionary<string, object>
{
{ "id", "devices"},
{ "class", "chosen-select form-control" },
{ "width", "100%" },
{ "data-placeholder", "Select Devices..." }
})
填充第二个下拉列表的jquery函数是
function groupSelected(obj) {
var selectedGroupId = obj.options[obj.selectedIndex].value;
$.ajax({
url: "../Devices/DevicesByGroupId",
type: "GET",
dataType: "JSON",
data: { groupId: selectedGroupId },
success: function (devicesData) {
$("#devices").html("");
$.each(devicesData, function (index, itemData) {
$("#devices").append(
$("<option></option>").val(itemData.Value).html(itemData.Text)
);
});
}
});
}
正在调用的 api 方法执行并返回数据,但由于某种原因,这些值未附加到第二个下拉列表中。
请建议我在这里缺少什么。
【问题讨论】:
-
你的类名建议你使用选择的插件。暂时禁用它并确认正在加载选项
标签: asp.net-mvc listbox jquery-chosen dropdown cascadingdropdown