我的 Telerik Kendo MVC UI 代码有问题。我的代码看起来很简单,但是当我将 '.CascadeFrom' 属性放在组合框上时,它会停止正确加载。这似乎与当我插入 javascript 函数的定义时它似乎没有注册的事实有关。我在
Web 开发者控制台:
[08:19:25.006] ReferenceError: getCountyVal is not defined in /Employer/Details/1
我想我已经将问题隔离到我使用 .CascadeFrom 属性或javascript函数的情况;当我不需要 javascript 调用或 JSON 返回服务器端代码中的输入变量时,我肯定能够加载。
前端代码:(2 个组合框,.cshtml 文件中的部分视图)
<td>
<p>
@(Html.Kendo().ComboBox()
.Name("countyselector")
.Placeholder("Select County....")
.DataTextField("NameStr")
.DataValueField("CountyTypeID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("getCountyTypes", "Employer");
});
}
)
//.Events(e => { e.Select("onCountySelectorSelect"); })
)
</p>
</td>
<td>
<p>
@(Html.Kendo().ComboBox()
.Name("countycityselector")
.Placeholder("Select City / Area...")
.DataTextField("NameStr")
.DataValueField("CountyCityTypeID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("getCityAreas", "Employer")
.Data("getCountyVal");
}).ServerFiltering(true);
}
)
.Enable(false)
.AutoBind(false)
.CascadeFrom("countyselector")
)
<script type="text/javascript">
function getCountyVal() {
return $("#countyselector").val();
}
</script>
控制器代码:
public JsonResult getCityAreas(int CountySel)
{
// Return a set of CountyCityAreaTypeID's and their associated names based on a countyID.
//return Json(db.vw_CountyCities.Where(x => x.CountyTypeId == Convert.ToInt16(CurrCountyValue))
// .Select(i => new { i.CountyCityAreatypeId, i.NameStr }), JsonRequestBehavior.AllowGet);
var retval = Json(db.vw_CountyCities
.Select(i => new { i.CountyCityAreatypeId, i.NameStr }), JsonRequestBehavior.AllowGet);
return retval;
}
public JsonResult getCountyTypes()
{
return Json(db.CountyTypes.Select(i => new { i.CountyTypeId, i.NameStr }), JsonRequestBehavior.AllowGet);
}