We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Preventing some records to be edited/deleted


Using EJ2, MVC5, VS2017, MySql, EF6

I´d like to be able to check records before editing or deleting them. Let´s say a record has a "satus" field where I must check its value and depending on that value (0, 1, etc) it can be edited or deleted, otherwise if its value is i.e. 3 it cannot be changed or deleted. 

Please, note I am using Razor, MVC5, EF6...

Is there a way to do it?

Thank you!

1 Reply

PS Pavithra Subramaniyam Syncfusion Team January 10, 2019 04:30 AM UTC

Hi Vanderlei, 
Thanks for contacting Syncfusion support. 
You can achieve your requirement by enabling the args.cancel property in the ‘actionBegin’ event with requestType “beginEdit” and “delete”. Please refer to the below code example and documentation link for further information. 
In the below demo, the rows which are having the value for ShipCountry column as “Denmark” is prevented from editing. 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).AllowPaging().Columns(col => 
        col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(30).Add(); 
        col.Field("CustomerID").HeaderText("Customer ID").Width(30).Add(); 
        col.Field("ShipCity").HeaderText("Ship City").Width(30).Add(); 
        col.Field("ShipCountry").HeaderText("Ship Country").Width(30).Add(); 
    }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).ActionBegin("actionBegin").Render() 
    function actionBegin(args) { 
        if (args.requestType === "beginEdit" || args.requestType === "delete") { 
            // you can check your required condition here 
            var data = args.rowData ? args.rowData : args.data[0]; 
            if (data.ShipCountry == "Denmark") {  
                args.cancel = true; 
Pavithra S. 

Live Chat Icon For mobile
Up arrow icon