0
@(Html.Kendo().Grid<TRC.Models.ProductModel>()
    .Name("Product")
    .HtmlAttributes(new { @Style = "align:center; font-size:12px; width:470px; height:100%" })
    .Columns(columns =>
    {


        columns.Bound(p => p.ProductId).Width(220);
        columns.Bound(p => p.ProductName).Width(220);
        columns.Bound(p => p.ProductCreateDate).EditorTemplateName("Date").Format("{0:dd/MM/yyyy}").Width(120);
        //columns.Command(commands => commands.Edit()).Width(100);
        columns.Command(commands => commands.Destroy());
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Sortable()
    .Selectable()
    .Scrollable(scrollable => scrollable.Virtual(true))
    .ColumnMenu(c => c.Columns(false))
    .DataSource(dataSource => dataSource
        .Ajax()//bind with Ajax instead server bind
        .ServerOperation(true)
            .Model(model =>
            {
                model.Id(p => p.ProductId);
                model.Field(p => p.ProductCreateDate).DefaultValue(DateTime.Now);
                model.Field(p => p.ProductCreateDate).Editable(false);

            })
            .Sort(sort => sort
            .Add(x => x.ProductCreateDate).Descending()
        )
        .Read(read => read.Action("GetProduct", "ProductDetails").Type(HttpVerbs.Get))
        .Destroy("DeleteProduct", "ProductDetails")
    )
)

控制器:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteProduct([DataSourceRequest] DataSourceRequest request, ProductModel model)
{
    if (model != null)
    {
        TRC_DataAccessLayer.SessionsList sList = db.GetProductbyId(model.ProductId);
        dbProduct.DeleteProduct(model.ProductId);
    }

    return View(GetProductData(request));
}
4

1 回答 1

0

Try this ->

Replace the following line in your markup

.Destroy("DeleteProduct", "ProductDetails")

with

.Destroy(update => update.Action("DeleteProduct", "ProductDetails"))

In your controller, replace

return View(GetProductData(request));

with

return Json(new[] { model}.ToDataSourceResult(request));
于 2013-11-04T20:17:24.743 回答