2013-03-02 71 views
0

網格和彈出窗口工作正常,除了我在創建模式下輸入的值不會傳回給我的控制器。查看JS控制檯顯示沒有錯誤。在Fiddler中監視創建過程也顯示沒有值被傳遞,雖然我的表單元素顯示。Kendo UI彈出窗口不傳遞值到控制器

調試時,我的控制器中的模型是空的。

這裏的電網定義:

@(Html.Kendo().Grid<MyApp.Domain.Entities.TaktInterruptionViewModel>() 
.Name("Interruptions") 
.Columns(columns => 
    { 
     columns.Bound(i => i.TaktInterruptionId).Hidden().IncludeInMenu(false); 
     columns.Bound(i => i.DateCreated).Title("Date").Width(75).Format("{0:d}"); 
     columns.Bound(i => i.ActionCount).Title("Actions").Width(50).Hidden(true); 
     columns.Bound(i => i.MeetingType).Title("Meeting Type").Width(100).Hidden(true); 
     columns.Bound(i => i.AreaName); 
     columns.Bound(i => i.TypeName); 
     columns.Bound(i => i.Responsible); 
     columns.Bound(i => i.Description).Width(300); 
     columns.Bound(i => i.Interruption).Width(75).Hidden(true); 
     columns.Bound(i => i.TaktMissed).Title("Missed").Width(75); 
    }) 
.ClientDetailTemplateId("ActionsTemplate") 
.ToolBar(toolbar => toolbar.Create().Text("Add Interruption")) 
.Editable(edit => edit.Mode(GridEditMode.PopUp).TemplateName("Create").Window(w => w.Title("Interruption").Name("addInterruption").Modal(true))) 
.DataSource(datasource => datasource.Ajax() 
    .Model(model => model.Id(p => p.TaktInterruptionId)) 
    .ServerOperation(false) 
    .PageSize(5) 
    .Create(create => create.Action("Create", "Home")) 
    .Read(read => read.Action("GetInterruptions", "Home"))) 
.Groupable() 
.Pageable() 
.Sortable() 
.Filterable() 
.ColumnMenu() 
.Selectable(s => s.Mode(GridSelectionMode.Multiple)) 
.Reorderable(reorder => reorder.Columns(true)) 
.Resizable(resize => resize.Columns(true)) 
.Events(events => events.Change("displayChart")) 
) 

我創建編輯模板如下:

@model MyApp.Domain.Entities.TaktInterruptionViewModel 
@{ 
    ViewBag.Title = "Index"; 
} 

<div class="span-14" style="padding: 10px;"> 
    @Html.ValidationSummary(true) 
    <hr class="space" /> 
    <div> 
     @Html.LabelFor(model => model.DateCreated)<br /> 
     @(Html.Kendo().DatePicker().Name("DateCreated").Value(DateTime.Today)) 
     <br /> 
     @Html.ValidationMessageFor(model => model.DateCreated, null, new { style = "color:red;" }) 
    </div> 
    <hr class="space" /> 
    <div class="span-7"> 
     @Html.LabelFor(model => model.AreaId)<br /> 
     @(Html.Kendo().DropDownListFor(model => model.AreaId) 
      .Name("AreaId") 
      .HtmlAttributes(new { style = "width:200px" }) 
      .OptionLabel("Select Area...") 
      .DataTextField("AreaName") 
      .DataValueField("AreaId") 
      .DataSource(source => 
       { 
        source.Read(read => 
         { 
          read.Action("GetAreas", "Area"); 
         }); 
       }) 
     ) 
     <br /> 
     @Html.ValidationMessageFor(model => model.AreaId) 
    </div> 
    <div class="span-6"> 
     @Html.LabelFor(model => model.TaktInterruptionTypeId)<br /> 
     @(Html.Kendo().DropDownListFor(model => model.TaktInterruptionTypeId) 
      .Name("TaktInterruptionTypeId") 
      .HtmlAttributes(new { style = "width: 200px" }) 
      .OptionLabel("Select Type...") 
      .DataTextField("TypeName") 
      .DataValueField("TaktInterruptionTypeId") 
      .DataSource(source => 
       { 
        source.Read(read => 
         { 
          read.Action("GetTypes", "Area").Data("filterTypes"); 
         }).ServerFiltering(true); 
       }) 
       .Enable(false) 
       .AutoBind(false) 
       .CascadeFrom("AreaId") 
     ) 
     <br /> 
     @Html.ValidationMessageFor(model => model.TaktInterruptionTypeId, null, new { style = "color:red;" }) 
    </div> 
    <hr class="space" /> 
    <div class="span-11"> 
     @Html.LabelFor(model => model.Description)<br /> 
     @Html.TextAreaFor(model => model.Description, new { @class = "multi-line" }) 
     <br /> 
     @Html.ValidationMessageFor(model => model.Description, null, new { style = "color:red;" }) 
    </div> 
    <hr class="space" /> 
    <div class="span-5"> 
     @Html.LabelFor(model => model.Interruption)<br /> 
     @(Html.Kendo().NumericTextBox().Name("Interruption").Format("#.0").Value(0)) 
     <br /> 
     @Html.ValidationMessageFor(model => model.Interruption) 
    </div> 
    <div class="span-6"> 
     @Html.LabelFor(model => model.TaktMissed)<br /> 
     @(Html.Kendo().NumericTextBox().Name("TaktMissed").Format("#.0").Value(0)) 
     <br /> 
     @Html.ValidationMessageFor(model => model.TaktMissed) 
    </div> 
    <hr class="space" /> 
    <div> 
     @Html.LabelFor(model => model.Responsible)<br /> 
     @Html.EditorFor(model => model.Responsible, new { @class = "k-input k-textbox" }) 
     <br /> 
     @Html.ValidationMessageFor(model => model.Responsible, null, new { style = "color:red;" }) 
    </div> 
    <hr class="space" /> 
    <hr class="space" /> 
</div> 

<script type="text/javascript"> 
    function filterTypes() { 
     return { 
     AreaID: $("#AreaId").val() 
     }; 
    } 
</script> 

我的控制器創建方法是:

[HttpPost] 
    public ActionResult Create([DataSourceRequest] DataSourceRequest request, MyApp.Domain.Entities.TaktInterruptionViewModel taktInterruption) 
    { 
     try 
     { 
      if (ModelState.IsValid) 
      { 
       // code removed for brevity 
      } 

      return Json(ModelState.ToDataSourceResult()); 
     } 
     catch(Exception ex) 
     { 
      TempData["message"] = "There was a problem saving the takt interruption.\n" + ex.Message; 
      return View(); 
     } 
    } 

如果我刪除我的編輯等式中的模板並允許kendo執行彈出窗口,信息傳遞給我的控制器;然而,我想控制彈出窗口的佈局,並且我還有級聯下拉菜單(即工作),因此也是編輯器模板。

我的問題是爲什麼我在傳入我的控制器的彈出窗口中輸入的值不是我的值?

+0

有人嗎?當然,有人曾經這樣做過。我很困難,需要幫助。謝謝! – SFAgitator 2013-03-05 16:13:57

回答

1

我不知道這是否是使用自定義編輯器模板的錯誤或限制,但是,爲了解決這個問題,我訂閱了JavaScript編輯事件並設置了下拉列表值。

function reassignVacancy_Editing(e) 
{ 
    e.preventDefault(); 

    var reassignUserList = $("#reassignUserList").data("kendoComboBox"); 

    reassignUserList.value(e.model.UserId); 
} 

我還需要處理保存事件和更新模型:

function reassignVacancy_Saving(e) 
    { 
     // Update the ViewModel 

     var reassignUserList = $("#reassignUserList").data("kendoComboBox"); 

     e.model.UserName = reassignUserList.dataItem().FullName; // For the benefit of the grid 
     e.model.UserId = reassignUserList.dataItem().Id;    
    } 

希望這有助於!

1

kendo彈出編輯,從網格中取值不是模板,當你輸入一個值時,模板修改新行的單元格。例如, ;

@(Html.Kendo().DatePicker().Name("DateCreated").Value(DateTime.Today)) 
@(Html.Kendo().NumericTextBox().Name("TaktMissed").Format("#.0").Value(0)) 

這些有一個默認值。如果您不更改其值,則不會將其張貼到控制器。發佈你必須寫入網格單元格的值。

var firstItem = $('#GridName').data().kendoGrid.dataSource.data()[0]; 
    firstItem.set('ColumnName', DefaultValue); 
+0

我被困在這個2小時。謝謝! – MattParra 2015-08-28 15:28:10

相關問題