0

我有两个下拉列表:

 @Html.DropDownListFor(model => model.Organization, (SelectList)ViewBag.Organizations)
 @Html.DropDownListFor(model=>model.Doctor, (SelectList)ViewBag.Doctors)

selectList 是从控制器传递的

        List<IOkpolu> orgs = _unitOfWork.Organizations.ToList();
        ViewBag.Organizations = new SelectList(orgs, "Code", "Name");

        List<IDoctor> docs = _unitOfWork.Doctors.GetAll().ToList();
        ViewBag.Doctors = new SelectList(docs, "Code", "Name");

我想根据运行时在第一个 DropDownList 中选择的组织代码加载第二个 DropDownList(Doctors)。对于医生,我有从组织中获取医生的方法:

_unitOfWork.Doctors.GetByOrganization(string organizationCode)

如何在运行时获取第一个 DropDownList 中选择的值并将其传递给第二个 DropDownList?

提前非常感谢!

4

1 回答 1

0

Doctors在您的控制器中,在运行时使用默认组织代码(列表中的第一项)加载您的列表orgs

    List<IOkpolu> orgs = _unitOfWork.Organizations.ToList();
    ViewBag.Organizations = new SelectList(orgs, "Code", "Name");

    model.Organization = orgs[0];

    List<IDoctor> docs = _unitOfWork.Doctors.GetByOrganization(model.Organization).ToList();
    ViewBag.Doctors = new SelectList(docs, "Code", "Name");
于 2013-07-29T05:00:36.400 回答