Eljay
Eljay

Reputation: 1

Kendo grid delete command not firing (MVC)

I setup a Kendo grid with an delete command.

Only the delete action is never fired when pushed on the delete button.

Here is my code:

view:

@(Html.Kendo().Grid<portal.Models.UserVisitor>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(v => v.visitorName).Filterable(false).Title("Visitors");
        columns.Command(command => command.Destroy());
    })
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Batch(true)
        .Model(model =>
        {
            model.Id(v => v.fkVisitorId);
            model.Field(v => v.visitorName).Editable(false);
        })
        .PageSize(20)
        .Read(read => read.Action("Visitors_Read", "Visitor"))
        .Destroy(update => update.Action("Visitors_Delete", "Visitor"))
     )
    .Resizable(resize => resize.Columns(true))
)

Controller Visitor:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Visitors_Delete([DataSourceRequest] DataSourceRequest request,UserVisitor model)
    {
        return Json(ModelState.ToDataSourceResult());
    }        

Does anyone know what is wrong with this??

Upvotes: 0

Views: 5853

Answers (2)

Jim
Jim

Reputation: 69

Try explicitly defining the action the grid should take.

.Destroy(update => update.Action("Visitors_Delete", "Visitor")).Type(HttpVerbs.Post))

Upvotes: 3

Atanas Korchev
Atanas Korchev

Reputation: 30671

You need to use InLine editing mode if you want the Destroy command to immediately hit the server:

@(Html.Kendo().Grid<portal.Models.UserVisitor>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(v => v.visitorName).Filterable(false).Title("Visitors");
        columns.Command(command => command.Destroy());
    })
    .Sortable()
    .Scrollable()
    .Filterable()
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Batch(true)
        .Model(model =>
        {
            model.Id(v => v.fkVisitorId);
            model.Field(v => v.visitorName).Editable(false);
        })
        .PageSize(20)
        .Read(read => read.Action("Visitors_Read", "Visitor"))
        .Destroy(update => update.Action("Visitors_Delete", "Visitor"))
     )
    .Resizable(resize => resize.Columns(true))
)

Upvotes: 4

Related Questions