有沒有方法可以在不使用CascadeFrom的情況下有兩個級聯下拉菜單(即手動觸發事件)?我不想使用CascadeFrom的原因是因爲我的父級和子級下拉式DataValueField都設置爲DataValueField(「ID」),因爲兩個模型中都具有相同的屬性名稱,如下所示。Kendo UI Cascading DropDownList不使用CascadeFrom
MODEL:
class ParentDropdownModel
{
public int ID { get; set; }
public string Name { get; set; }
}
class ChildDropdownModel
{
public int ID { get; set; }
public string Name { get; set; }
}
VIEW:
@(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);
}