2012-07-14 19 views
3

我正在使用asp.net mvc剃刀處理Kendo UI。我試圖用支持CRUD操作的kendo網格綁定數據庫表數據。在這裏,我需要填充我的表格字段之一的下拉列表。我用下面的代碼我怎樣才能得到從下拉列表中選擇的值在kendo ui網格中的mvc

查看:

@model IEnumerable<MvcApplication1.PriceOption>  
@(Html.Kendo().Grid(Model) 
     .Name("Grid") 
     .Columns(columns => 
     { 
      //columns.Bound(p => p.ProductTitle).ClientTemplate("<input type='checkbox' disabled='disabled'name='Discontinued' <#= Discontinued? checked='checked' : '' #> />"); 
      columns.Bound(p => p.ProductTitle).EditorTemplateName("OptionalEmail"); 
      columns.Bound(p => p.OptionTitle); 
      columns.Bound(p => p.Price); 
      columns.Bound(p => p.Frequency); 
      columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200); 



     }) 
     .ToolBar(toolbar => toolbar.Create()) 
      .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine)) 
     .Pageable() 
     .Sortable() 
     .Scrollable() 
     .DataSource(dataSource => dataSource 
      .Ajax() 
      .Events(events => events.Error("error_handler")) 
      .Model(model => model.Id(p => p.ProductID)) 
      .Create(create => create.Action("CreateOption", "ZiceAdmin")) 
      .Read(read => read.Action("Read", "ZiceAdmin")) 
      .Update(update => update.Action("UpdateOption", "ZiceAdmin")) 
      .Destroy(update => update.Action("DeleteOption", "ZiceAdmin")) 
     ) 
    ) 

OptionalEmail.cshtml

@model string 
@(Html.Kendo().DropDownList() 
    .Name("ProductTitle") 
    .Value(Model) 
    .SelectedIndex(0) 
    .BindTo(new SelectList(ViewBag.ProductTitle)) 
) 

在這裏,我需要選擇的項目從下拉列表存儲。但它總是顯示爲空。我怎麼能從dropdownlist中獲得選定的值。

回答

-1

這是一個錯誤。刪除的名稱,它將提交回服務器作爲ViewModel的一部分:

@model string 
@(Html.Kendo().DropDownList() 
    .Value(Model) 
    .SelectedIndex(0) 
    .BindTo(new SelectList(ViewBag.ProductTitle)) 
) 
+0

名稱值必須不爲空..描述:在當前Web請求的執行過程中'出現未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及它在代碼中的起源。 異常詳細信息:System.ArgumentNullException:值不能爲空。 – 2013-08-20 16:35:14

相關問題