This is a migrated thread and some comments may be shown as answers.

Row Destroy command to call controller

3 Answers 688 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 16 Jan 2019, 03:33 PM

I am attempting to call a function in the controller when the Destroy button is clicked on a row. The controller will then delete the record in the database. I also need to pass in the ID of the employee to identify which record in the database to delete. Thank you!

This is what I have:

@(Html.Kendo().Grid<TelerikAspNetCoreApp1.Models.EmployeeViewModel>()
    .Name("grid")
    .ToolBar(toolbar => toolbar.Create().Text("ADD").HtmlAttributes(new { title = "Add Employee" }))
    .Columns(columns =>
    {
        columns.Bound(p => p.EmployeeName);
        columns.Bound(p => p.Active);
        columns.Command(command =>
        {
            command.Destroy().HtmlAttributes(new { title = "Delete Highlighted Employee" });
        }).Width(150);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:450px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Employee_Read", "Grid"))
        .Destroy(update => update.Action("Employee_Delete", "Grid"))
    )
)

3 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 18 Jan 2019, 11:43 PM
To clarify, "Employee_Read" is getting called and the data is displayed just fine. However, "Employee_Delete" is not getting called when I confirm a deletion of the row.
0
Accepted
Viktor Tachev
Telerik team
answered on 21 Jan 2019, 11:33 AM
Hi Mark,

In order for the CRUD operations to work as expected there should be an ID field specified in the DataSource Model. Modify the DataSource configuration so it uses specific field for ID and the delete operation should work as expected:

.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Model(model => model.Id(p => p.EmployeeID))
    .Read(read => read.Action("Employee_Read", "Grid"))
    .Destroy(update => update.Action("Employee_Delete", "Grid"))
)


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mark
Top achievements
Rank 1
answered on 21 Jan 2019, 05:53 PM
Thank you so much! I spent too long trying to get this to work and now it does.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or