2013-07-11 58 views
0

我遇到Telerik Kendo MVC UI代碼出現問題。我的代碼看起來很漂亮,但是當我將'.CascadeFrom'屬性放在組合框上時,它會停止正確加載。這似乎與這樣一個事實有關,即當我插入javascript函數的定義時,它似乎沒有註冊。我在Telerik Kendo MVC級聯Combobox問題

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); 
} 
+0

這個問題已經成爲流行,我已經不知道相關的答案是否正常工作。如果答案解決了您的問題,請留下評論,以便我可以接受。 –

回答

1

請把下面的代碼段中的其他的代碼/標記的開始。

JS

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

OR

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