2

我创建了可以创建、更新和删除数据的 Kendo UI Grid。但它不是在我的控制器中触发更新操作。

这是我的代码:

<script src="~/Scripts/Kendo/jquery.min.js"></script>
<script src="~/Scripts/Kendo/kendo.all.min.js"></script>
<script src="~/Scripts/Kendo/kendo.aspnetmvc.min.js"></script>

@(Html.Kendo().Grid<SkuMetadata>()
  .Name("Grid")
  .Columns(colums =>
               {
                   colums.Bound(p => p.CompanyName).Width(100);
                   colums.Bound(p => p.BrandName).Width(100);
                   colums.Bound(p => p.ProductName).Width(100);
                   colums.Bound(p => p.SkuName).Groupable(false).Width(100);
                   colums.Command(command => { 
                       command.Edit();
                       command.Destroy(); }).Width(160);
               })
  .ToolBar(toolbar => toolbar.Create())
  .Editable(editable => editable.Mode(GridEditMode.PopUp))
      .Groupable()
      .Pageable()
      .Sortable()
      .Scrollable()
      .Filterable()

  .HtmlAttributes(new { style = "height: 500px;" })
  .DataSource(dataSource =>
              dataSource
                  .Ajax()     
                  .Batch(true)
                  .ServerOperation(false)
                  .PageSize(100)
                  .Events(events => events.Error("error_handler"))
                  .Model(model => model.Id(p => p.SkuId))
                  .Create(update => update.Action("CreateProducts", "Product"))
                  .Update(update => update.Action("UpdateProducts", "Product").Type(HttpVerbs.Post))
                  .Destroy(destroy => destroy.Action("DeleteProducts", "Product"))
                  .Read(read => read.Action("GetAllProducts", "Product"))))

我的行动是:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult UpdateProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
    {
        return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
    }
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DeleteProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
    {

        return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
    }

创建和删除工作正常。我不明白为什么更新不起作用。我是否错过了任何参考或我做错了什么?

4

5 回答 5

4

用这个

 .DataSource(dataSource =>
          dataSource
              .Ajax()     
              .Batch(true)
              .ServerOperation(false)
              .PageSize(100)
              .Events(events => events.Error("error_handler"))
         ---->**.Model(model => { model.Id(p => p.ID); model.Field(p => p.ID).DefaultValue(16000000); })** <--------
              .Create(update => update.Action("CreateProducts", "Product"))
              .Update(update => update.Action("UpdateProducts", "Product").Type(HttpVerbs.Post))
              .Destroy(destroy => destroy.Action("DeleteProducts", "Product"))
              .Read(read => read.Action("GetAllProducts", "Product"))))
于 2013-06-11T03:03:25.203 回答
0

我会首先将网格退出批量编辑模式,看看在更新弹出窗口中的记录后是否可以触发更新操作。

于 2013-06-10T14:20:30.430 回答
0

您必须将 ServerOperation(false) 更改为 ServerOperation(true)

于 2014-07-21T04:57:52.407 回答
0

尝试使用[GridAction]属性标记动作。

并且可能您必须编写如下操作:

[AcceptVerbs(HttpVerbs.Post)]  
[GridAction]  
public ViewResult(...)  
{  
//do what you need..and if .ToDataSourceResult(..) return IEnumerable try write  
var model = _basicUnit.Skus.GetAllSku().ToDataSourceResult(request);  
return View(new GridModel(model));  
} 
于 2013-06-10T14:14:59.877 回答
0

在您的渲染操作中,您必须在模型中发送 ID 值。

[PopulateViewData("PopulateViewData")]
public virtual ActionResult Novo()
{
    domain = ...;
    var model = new Model
    {
        Id = model.Id,
        Propertyx = model.PropertyX,
        ...
    };
 return View(model);
 }
于 2014-11-19T18:37:20.387 回答