我有三个剑道下拉列表,如下所示
1)
@(Html.Kendo().DropDownListFor(m => m.ProgrammeID)
.HtmlAttributes(new { data_value_primitive = "true" })
.Name("ProgrammeID")
.DataTextField("DegreeName")
.DataValueField("Id")
.OptionLabel("Select Below...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetProgramme", "AptitudeTset").Data("filterProgramme");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
.CascadeFrom("FacultyID")
)
2)
@(Html.Kendo().DropDownListFor(m => m.SpecializationID)
.HtmlAttributes(new { data_value_primitive = "true" })
.Name("SpecializationID")
.DataTextField("SpecializationNameID")
.DataValueField("SpecializationID")
.OptionLabel("Select Below...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetSpecialization", "Subject").Data("filterSpecialization");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
.CascadeFrom("ProgrammeID")
)
3)
@(Html.Kendo().DropDownListFor(m => m.SemesterID)
.HtmlAttributes(new { data_value_primitive = "true" })
.OptionLabel("Select Below...")
.Name("SemesterID")
.DataTextField("SemesterName")
.DataValueField("SemesterID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetSemester", "StudentRSRegistration").Data("loadSemester");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
.CascadeFrom("SpecializationID")
.CascadeFrom("ProgrammeID"`enter code here`)
)
在这里我的第3次DDL负载基于1st&第二个DDL。但有时候第二次DDL可能没有价值。它可以是空的.1d DDL总是有值。我的问题是,当第二个DDL为空值时,我的第三个DDL没有加载。但我想总是加载我的第三个DDL。因为SemesterID是需要的。 SemesterID取决于programmeID 或/和 SpecializationID。这就是为什么有些时候第二个DDl可能有空值。
答案 0 :(得分:1)
我使用Ajax调用解决了这个问题。我使用了第二个DDL级联事件Handel,如下所示 的 .Events(M => m.Cascade(" cascadesp&#34))强>
现在是我的第二个DDL
@(Html.Kendo().DropDownListFor(m => m.SpecializationID)
.HtmlAttributes(new { data_value_primitive = "true" })
.Name("SpecializationID")
.DataTextField("SpecializationNameID")
.DataValueField("SpecializationID")
.OptionLabel("Select Below...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetSpecialization", "Subject").Data("filterSpecialization");
})
.ServerFiltering(true);
})
.Events(m=>m.Cascade("cascadesp"))
.SelectedIndex(0)
.CascadeFrom("ProgrammeID")
)
我的ajax电话是
function cascadesp()
{
getSemesterID($("#ProgrammeID").data("kendoDropDownList").value(),$("#SpecializationID").data("kendoDropDownList").value(),$("#SpecializationLevelID").data("kendoDropDownList").value(),$("#IntakeID").data("kendoDropDownList").value(),$("#intakeYear").val());
}
function getSemesterID(ProgrammeID, SpecializationID, SpecializationLevelID, IntakeID, intakeYear)
{
var ddl = $('#SemesterID').data("kendoDropDownList");
var URL = "/StudentRSRegistration/GetSemester/";
$.ajax({
url: URL,
data: JSON.stringify({ ProgrammeID: ProgrammeID, SpecializationID: SpecializationID, SpecializationLevelID: SpecializationLevelID, IntakeID: IntakeID, intakeYear: intakeYear }),
async: false,
cache: false,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
ddl.setDataSource(data);
}
});
}
现在我的SemeterID DDL正在loding