2013-01-02 71 views
1

我試圖使用kendo dropdownlist並使用模板方法呈現選項http://demos.kendoui.com/web/dropdownlist/template.html(單擊ASP.NET MVC> template.cshtml)。爲了簡化這個問題,我只是試圖僅顯示AccountDescription。Kendo dropdown - 模板

這是我的代碼到目前爲止。

CSHTML

...   
    <div class="editor-field"> 
     <script> 
      function entityFiltering() { 
       return { 
        entityId: $("#EntityId").val() 
       }; 
      } 
     </script> 

     @(Html.Kendo().DropDownListFor(m => m.AccountNumber) 
      .Name("AccountNumber") 
      .DataTextField("AccountShortCode") 
      .DataValueField("AccountNumber") 
      .Template("<table><tr><td width='100px'>${ data.AccountDescription } </td></tr></table>") 
      .OptionLabel("Please select...") 
      .DataSource(source => source.Read(read => read.Action("ActionName", "ControllerName") 
                 .Data("entityFiltering")) 
            .ServerFiltering(true)) 
      .Enable(false) 
      .AutoBind(false) 
      .CascadeFrom("EntityId") 
      ) 
     @Html.ValidationMessageFor(m => m.SourceAccountNumber) 
    </div> 
    ... 

這個模型看起來像

public class Model { 

    [Required] 
    [Display(Name = "Short Code")] 
    public string AccountShortCode { get; set; } 

    [Required] 
    [Display(Name = "Account Number")] 
    [ScaffoldColumn(false)] 
    public int AccountNumber { get; set; } 

    [Required] 
    [Display(Name = "Description")] 
    [ScaffoldColumn(false)] 
    public string AccountDescription { get; set; } 
} 

當下拉列表中呈現的所有選項都在列表中,但它們顯示undefined如果我選擇一個選項,我可以看到實際的正確的值綁定在網格上,所以我認爲我的問題純粹是一個顯示問題。

+0

瀏覽器開發人員工具中的JSON是什麼樣的?您是否嘗試從模板中的字段中取出「數據」前綴? –

+0

分享這個動作看起來如何 - > read.Action(「ActionName」,「ControllerName」) 而且Burke建議在Dev Tools/Firebug內部的網絡選項卡內共享什麼。 –

回答

3

幾個小時後我設法排序!我將模板中的語法更改爲#= data.AccountDescription #,這就完成了!

+0

謝謝,節省了我幾個小時,簡單又不錯的解決方案 – joeriks

+0

這完全是我的問題,您的解決方案也解決了我的問題,所以感謝您發佈! –