【发布时间】:2014-08-21 17:21:24
【问题描述】:
我有一个包含公司列表的下拉列表,我还有另一个包含公司分支机构列表的下拉列表。我需要使分支下拉列表依赖于公司选定的项目。因此,当用户从下拉列表中选择 company1 时,分支下拉列表应将列表填充到 company1 中的分支。我不知道该怎么做。这是我的下拉菜单的样子:
<tr>
<td class="search-label">
@Html.Label("Company: ")
</td>
<td>
@Html.DropDownList("cono", (List<SelectListItem>)ViewBag.CompanyList)
</td>
</tr>
<tr>
<td class="search-label">
@Html.Label("Branch: ")
</td>
<td>
@Html.DropDownList("branch", (List<SelectListItem>)ViewBag.BranchList)
</td>
</tr>
这是我的操作:
[HttpGet]
public ActionResult Default()
{
var currentUserCono = GetCurrentUserCono();
//Set the Viewbags to populate the drop down menus on the view
if (Session["cono"] != null)
{
currentUserCono = (int)Session["cono"];
}
ViewBag.CompanyList = _selectListLib.GetCompanies(currentUserCono);
ViewBag.BranchList = Session["branch"] != null ? _selectListLib.GetBranches(currentUserCono,(string)Session["branch"]) : _selectListLib.GetBranches(currentUserCono);
ViewBag.StatusTypeList = Session["statustype"] != null ? _selectListLib.GetStatusTypes((bool)Session["statustype"]) : _selectListLib.GetStatusTypes();
return View();
}
【问题讨论】:
-
只需使用我的 jquery 插件github.com/fals/jquery-cascadeselect 这将使您的生活变得轻松
-
使用 Ajax 级联可以解决。
-
是的@ArijitMukherjee,这就是我的插件自动执行的操作!!! :D github.com/fals/jquery-cascadeselect
-
谢谢你们!我将对此进行调查。这看起来是我现在最好的选择哈哈
标签: jquery asp.net-mvc-4 razor selectlist