I am new to Telerik, I am getting in the options list of the drop down list "years" Undefined instead of 2017, 2015, ...
Any help is appreciated. Below are the codes.
This is the view:
@(Html.Kendo().DropDownList()
.Name("years")
.HtmlAttributes(new { style = "width:100%" })
.OptionLabel("Select year...")
.DataTextField("YearName")
.DataValueField("YearCode")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCascadeYears","Home");
});
})
)
and this is the controller:
public JsonResult GetCascadeYears()
{
IQueryable years = Year.GetYears();
if (HttpContext.Request.IsAjaxRequest())
{
return Json(new SelectList(
years,"YearCode", "YearName"), JsonRequestBehavior.AllowGet
);
}
return View(years);
}
and this the model:
public class Year
{
public int YearCode { get; set; }
public String YearName { get; set; }
public static IQueryable<Year> GetYears()
{
return new List<Year>
{
new Year {
YearCode = 1,
YearName = "2017"
},
new Year{
YearCode = 2,
YearName = "2015"
},
new Year{
YearCode = 3,
YearName = "2014"
},
new Year{
YearCode = 4,
YearName = "2010"
},
}.AsQueryable();
}
}
Regards