有没有办法在不使用 CascadeFrom 的情况下拥有两个级联下拉菜单(即手动触发事件)?我不想使用 CascadeFrom 的原因是,由于两个模型中的属性名称相同,我的父级和子级下拉菜单 DataValueField 都设置为 DataValueField("ID"),如下所示。
型号:
class ParentDropdownModel
{
public int ID { get; set; }
public string Name { get; set; }
}
class ChildDropdownModel
{
public int ID { get; set; }
public string Name { get; set; }
}
查看:
@(Html.Kendo().DropDownList()
.AutoBind(true)
.Name("ddlParent")
.DataTextField("Name")
.DataValueField("ID")
.OptionLabel("Select a parent...")
.DataSource(ds => ds.Read(read => read.Action("ReadParent", "Home")))
.Events(e => e.Change("OnParentChanged"))
)
@(Html.Kendo().DropDownList()
.AutoBind(false)
.Name("ddlChild")
.DataSource(ds => ds.Read(read => read.Action("FilterChild", "Home").Data("filterChild")))
.DataTextField("Name")
.DataValueField("ID")
.OptionLabel("Select a child...")
)
<script type="text/javascript">
function OnParentChanged(e)
{
var child = $('#ddlChild').data("kendoDropDownList");
child.dataSource.read(filterChild());
}
function filterChild()
{
var myid = $("#ddlParent").val();
return
{
parentID: $("#ddlParent").val()
};
}
</script>
控制器:
public ActionResult FilterChild([DataSourceRequest] DataSourceRequest request, string parentID)
{
// Here is the Problem: parentID is null at run-time
return Json(dummyData, JsonRequestBehavior.AllowGet);
}