3天前我开始学习ASP.NET和telerik,我需要一些关于级联下拉列表的帮助,我真的无法检测到问题的根源,我需要帮助。
以下是代码
以下是观点:
@(Html.Kendo().DropDownList()
.Name("months")
.HtmlAttributes(new { style = "width:100%" })
.OptionLabel("Select month...")
.DataTextField("MonthName")
.DataValueField("MonthID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCascadeMonths", "Home")
.Data("filterMonths");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("years")
)
<script>
function filterMonths() {
return {
years: $("#years").val()
};
}
</script>
这是控制器:
public ActionResult GetCascadeMonths(int YearCode)
{
IQueryable months = Month.GetMonths().Where(x => x.YearCode == YearCode);
if (HttpContext.Request.IsAjaxRequest())
return Json(
months,
JsonRequestBehavior.AllowGet
);
return View(months);
}
这是模型:
public class Month
{
public int YearCode { get; set; }
public int MonthID { get; set; }
public String MonthName { get; set; }
public static IQueryable<Month> GetMonths()
{
return new List<Month>
{
new Month
{
YearCode = 1,
MonthID=1,
MonthName = "January"
},
new Month
{
YearCode = 1,
MonthID=2,
MonthName = "February"
},
new Month
{
YearCode = 1,
MonthID=3,
MonthName = "March"
},
new Month
{
YearCode = 1,
MonthID=4,
MonthName = "April"
},
new Month
{
YearCode = 1,
MonthID=5,
MonthName = "May"
},
new Month
{
YearCode = 1,
MonthID=6,
MonthName = "June"
}
}.AsQueryable();
}
}
如果您有任何想法,请告诉我。 提前谢谢。