我的视图中有三个下拉框,代码为
public class IntFoo implements Foo<Integer>
{
public <synthetic> <bridge> Object moo()
{
return Integer.valueOf(this.moo());
}
public int moo()
{
return 0;
}
}
我的控制器GET操作方法是
IntFoo intFoo = new IntFoo();
Foo<Integer> foo = intFoo;
Integer i = foo.moo(); // calls the synthetic method, which boxes the result of the actual implementation
在数据库中,@Html.DropDownList("EventGroupTitle", ViewData["groupList"] as List<SelectListItem>, new { @class = "form-control" })
@Html.DropDownList("EventGroupName", ViewData["groupNameList"] as List<SelectListItem>, new { @class = "form-control" })
@Html.DropDownList("EventTypeOne", ViewData["typeList"] as List<SelectListItem>, new { @class = "form-control" })
和 public ActionResult Create()
{
List<SelectListItem> liEventGroups = new List<SelectListItem>();
List<SelectListItem> liEventTypes = new List<SelectListItem>();
List<SelectListItem> liEventGroupNames = new List<SelectListItem>();
// pull results from DB and assign them to the above variables
ViewData["typeList"] = liEventTypes;
ViewData["groupList"] = liEventGroups;
ViewData["groupNameList"] = liEventGroupNames;
return View();
}
之间存在一对多的关系。例如,组标题可以是EventGroupTitle
,组名称可以是EventGroupNames
,Doctor
。另一个组标题为Dr Joe
,因此组名称为Dr Adrian
,Nurse
。
没有实际的外键设置,但Nurse Daniel
中有一个字段说明Nurse Dave
是什么。
那么有没有办法对Dropbox进行某种过滤?如果他们在第一个保管箱中选择GroupNames
,那么我只希望医生出现在第二个保管箱中。
答案 0 :(得分:0)
我在这里创建了级联下拉式html帮助器。它以nuget package形式提供,测试的源代码在github上。
用法非常简单。例如,您有一个国家/地区的城市下拉菜单 使用以下模型:
<强>模型强>:
public class Model
{
public int SelectedCountry {get;set;}
public IList<SelectListItem> Countries {get;set;}
public int SelectedCity {get;set;}
}
<强>控制器强>
public ActionResult GetCities(int country)
{
//return IList<SelectListItem> of Cities based on a country that you get as a parameter
}
查看强>
//First simple dropdown
@Html.DropDownListFor(m=>m.SelectedCountry, Model.Countries,
"Please select a Country", new {@class="form-control"})
//Dropdown list for SelectedCity property that depends on selection of SelectedCountry property
@Html.CascadingDropDownListFor(
expression: m => m.SelectedCity,
triggeredByProperty: m => m.SelectedCountry, //Parent property that trigers dropdown data loading
url: Url.Action("GetCities", "Home"), //Url of action that returns dropdown data
actionParam: "country", //Parameter name for the selected parent value that url action receives
optionLabel: "Please select a City", // Option label
disabledWhenParrentNotSelected: true, //If true, disables dropdown until parrent dropdown selected
htmlAttributes: new { @class = "form-control" }) //Html attributes