0

我的 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);
}
4

1 回答 1

1

请把下面的代码片段放在其他代码/标记的开头。

JS

 <script type="text/javascript">
        function getCountyVal() {
            return {
                CountySel: $("#countyselector").data("kendoComboBox").input.val()
            };
        }
    </script>

或者

    <script type="text/javascript">
         function getCountyVal() {
             return {
                 CountySel: $("#countyselector").val()
             };
         }
    </script>
于 2013-07-13T10:01:06.330 回答