2014-02-12 174 views
1

我的頁面中有一個kendo UI網格。下面是帶有CRUD數據源操作的kendo UI網格的代碼。Kendo UI Grid多次觸發

@(Html.Kendo().Grid<Gts.GlaspacLX.Web.ViewModel.ProductViewModel>() 
     .Name("xyzGrid") 
     .Columns(columns => 
      { 
       columns.Bound(p => p.SelectedProductCategory).EditorTemplateName("_ProductDropDownList").Title("Product Category").HtmlAttributes(new { @tabindex = "8" }); 
       columns.Bound(p => p.Name).Width(130).Title("% Off").HtmlAttributes(new { @tabindex ="9" }); 
       columns.Bound(p => p.Rate).Width(130).HtmlAttributes(new { @class = "prodDiscRtAlign",@tabindex= "10" }); 
       columns.Bound(p => p.Hours).Width(130).HtmlAttributes(new { @class = "prodDiscRtAlign",@tabindex= "11" }); 
       if (SiteContext.CurrentUser.HasPrivilege(PrivilegeNames.Maintenance, PermissionNames.DELETE)) 
       { 
        columns.Command(command => { command.Destroy(); }).Width(110).Title("Delete").HtmlAttributes(new { @tabindex = "12" }); 
       } 
      }) 
     .ToolBar(commands => 
      { 
       commands.Create(); 
       commands.Save(); 
      }) 
     .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom)) 
     .Sortable() 
     .Navigatable() 
     .DataSource(dataSource => dataSource 
            .Ajax() 
            .Batch(true) 
            .ServerOperation(false) 
            .Model(model => 
             { 
              model.Id(p => p.ProductID); 
              model.Field(p => p.SelectedProductCategory).DefaultValue(ViewBag.DefaultProductCategory); 
             })            
            .Read(read => read.Action("Product_Read", "ProductController")) 
            .Update(update => update.Action("Product_Update", " ProductController ")) 
            .Create(create => create.Action("Product_Create", " ProductController ")) 
            .Destroy(update => update.Action("Product_Destroy", " ProductController ") 
            )) 
     .Events(e => e.Edit("proField").DataBound("boundProductChange")) 
    ) 

以下僅僅是劍道網後「保存」按鈕的屏幕截圖。它負責任何頁面的創建/更新操作。

enter image description here

我的問題是,一旦我點擊保存按鈕任何創建或更新操作其發佈的操作方法的兩倍。你可以看到上面的屏幕截圖的控制檯。

下面是一張我的控制器的操作方法的代碼:

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Product_Create([DataSourceRequest] DataSourceRequest request,  [Bind(Prefix = "models")]IEnumerable<ProductViewModel> product){ 
     return Json(results.ToDataSourceResult(request, ModelState)); 
    } 

下面是proField功能代碼: -

function proField(e) { 
    var defaultproduct = $("#DefaultProductCategory").val(); 
    defaultproduct = "\n" + defaultproduct + "select "; 
    if (e.model.SelectedProductCategory == "Default" && (e.sender._editContainer[0].textContent == defaultproduct || e.sender._editContainer[0].textContent == "\n select ")) { 
      e.sender._editContainer[0].disabled = true; 
      e.sender._editContainer[0].children[0].textContent = "Default"; 
      e.sender.table[0].rows[1].cells[1].click(); 
      e.sender.table[0].rows[1].cells[4].disabled = true; 
    } 

}

+0

你可以分享'proField'函數的代碼嗎? – EfrainReyes

+0

@EfrainReyes我已添加proField功能。 – Pawan

+0

您是否也可以分享「boundProductChange」 – MustafaP

回答

1

插入任何後記錄你應該返回主要(Id)鍵來查看。 查看kendo演示。

+0

@lraj我檢查它與返回隨機數。但結果是相同的。問題是事件在「保存」按鈕點擊時發射。意味着一旦我們點擊保存按鈕,多個事件正在發射。 – Pawan

+0

你確定嗎?我不知道這件事。 檢查此: http://stackoverflow.com/questions/16726705/kendo-grid-duplicate-records-inserted?answertab=votes#tab-top – Iraj