2016-07-15 112 views
-1

我正在使用Telerik MVC 4.我想製作一個組合框和下拉列表。但它總是顯示文本框。如何使用Kendo UI進行下拉

這是控制器

[Authorize] 
     public JsonResult GetProvinsiByJSON() 
     { 
      var propinsi = db.Tbl_Propinsi.Where(b => b.flag == "Y").Select(b => new { Value = b.id_propinsi, Text = b.propinsi }).AsEnumerable(); 
      return Json(propinsi, JsonRequestBehavior.AllowGet); 
     } 

這是我的看法

@{ 
    ViewBag.Title = "Kota"; 
    Layout = "~/Views/Shared/_adminLayout.cshtml"; 
} 

<div class="tables"> 
    <div class="table-responsive bs-example widget-shadow"> 
     <h4>Data Kota:</h4> 
     <div> 
      <form> 
       <div class="form-group"> 
        <label for="kategori">Tambah Kota</label> 
        <br/> 
        @(Html.Kendo().ComboBox() 
         .Name("provId") 
         .Placeholder("Pilih Provinsi") 
         .DataTextField("Text") 
         .DataValueField("Value") 
         .HtmlAttributes(new { style = "width:100%;" }) 
         .Filter("contains") 
           .DataSource(source => { source.Read(read => read.Action("GetProvinsiByJSON", "Lokasi")); }) 
        ) 
        @(Html.Kendo().DropDownList() 
         .Name("provID") 
         .OptionLabel("Please select Provinsi ...") 
         .HtmlAttributes(new { style = "width:40%" }) 
         .DataTextField("Text") 
         .DataValueField("Value") 
         .Filter("contains") 
         .DataSource(source => { source.Read(read => read.Action("GetProvinsiByJSON", "Lokasi")); }) 
        ) 
        <input type="text" class="form-control" id="kota" name="kota" placeholder="Nama Kota"> 
        <button type="submit" class="btn btn-default">Simpan</button> 
       </div> 
      </form> 
     </div> 
     <table class="table table-bordered"> 
      <thead> 
       <tr> 
       <th>No</th> 
       <th>Kota</th> 
       <th>Provinsi</th> 
       </thead> 
       <tbody> 

       </tbody> 
     </table> 
    </div> 
</div> 

這是我所得到的,只是一個空的文本框

enter image description here

請幫助我。先進的感謝

+0

請注意,模型 - 視圖 - 控制器標籤是關於模式的問題。 ASP.NET-MVC實現有一個特定的標籤。 –

+0

根據我的經驗,這種行爲通常來自Kendo UI視圖中存在的Javascript錯誤。請使用瀏覽器的開發人員工具檢查您的瀏覽頁面,並在此處顯示錯誤信息 –

回答

2

這很可能是由於JavaScript錯誤或缺少Kendo UI所需的資源造成的。

爲了劍道UI腳本按預期工作,請確保您 包括 前的腳本文件中對jQuery庫的引用。

請在以下鏈接看看:

http://docs.telerik.com/kendo-ui/intro/installation/prerequisites#javascript-prerequisites http://docs.telerik.com/kendo-ui/intro/installation/getting-started#host-kendo-ui-in-your-project

希望這有助於。

+0

是的,謝謝你,但數據庫中的數據仍然無法填充。你知道爲什麼嗎? –

相關問題