Error - Cannot read properties of undefined (reading 'result'

Hello. I have the following problem:

If I press "Add" followed by "Cancel" this error in console.log appears.

1.png


Controller Data Source: 

        [HttpPost]

        public ActionResult HierarchyResourcePermissionsDataSource(DataManager dm)

        {

            if (dm.Take == 0) dm.Take = 20; 

            var orderBy = DataManagerHelper.OrderBy(dm);

            var whereConditions = DataManagerHelper.WhereConditions(dm);

            var procedureName = "GetHierarchyResourcePermissions";

            var dt = DataManagerHelper.GetDataFromProcedure(procedureName,

                whereConditions, orderBy, dm.Skip, dm.Take, this.GetExtraParameters());

            var count = this.GetCount(procedureName, whereConditions,dm.Skip, this.GetExtraParameters());

            IEnumerable data = Utils.DataTableToJson(dt);

            return this.Json(new {result = data, count});

        }

Index.cshtml Grid:

        @(Html.EJS().Grid<HierarchyResourcePermission>

    ("HierarchyResourcePermissionsGrid")

            .DataSource(datasource => datasource.Url(Url.Action("HierarchyResourcePermissionsDataSource", "HierarchyPermission")).Adaptor("UrlAdaptor"))

            .Locale(CultureHelper.GetCurrentCultureEntireName())

            .EditSettings(edit => edit.AllowAdding(true).AllowDeleting(true).AllowEditing(true))

            .ActionComplete("actionComplete")

            //.ClientSideEvents(eve => eve.EndEdit("endAddOrEdit").EndAdd("endAddOrEdit").EndDelete("endDelete").ActionComplete("startEventResource"))

            //.EnablePersistence(true)

            .Toolbar(new List<string>()

            {

                "Add",

                "Edit",

                "Update",

                "Cancel",

                "Delete"})

            .AllowSorting()

            .AllowFiltering()

            .AllowPaging()

            .PageSettings(page => page.PageSize(20).PageCount(this.Request.IsMobileLayout() ? 2 : 8))

            .AllowResizing()

            .Columns(col =>

            {

                col.Field("Id").IsPrimaryKey(true).Visible(false).Add();

                col.Field("ResourceLabel").HeaderText(Translations.Get("Resource")).Add();//.ValidationRules(new { required = true }).Add();

                col.Field("ResourceTypeName").HeaderText(Translations.Get("ResourceType")).AllowEditing(false).Add();

                col.Field("UserName").HeaderText(Translations.Get("User")).Add();//.ValidationRules(new { required = true }).Add();

                col.Field("RoleName").HeaderText(Translations.Get("Role")).AllowEditing(false).Add();

                col.Field("OrgChartName").HeaderText(Translations.Get("OrganizationChart")).AllowEditing(false).Add();

            }).Render())


Index.js:

function actionComplete(args) {


    if (args.requestType === "save") {

        endAddOrEdit(args);

    } else if (args.requestType === "delete") {

        endDelete(args);

    } else if ((args.requestType === "beginedit" || args.requestType === "add")) {

        var gridObj = document.getElementById

            ("HierarchyResourcePermissionsGrid").ej2_instances[0];

        // Autocomplete resurse

        var autoCompleteResourceLabel = new ej.dropdowns.AutoComplete({

            dataSource: window.dataManagerResource,

            fields: { "text": "value", "key": "id" },

            width: "100%",

            emptyResultText: window.noResultMessage,

            value: args.rowData.Value,

            select: function (argument) {

                document.getElementById("HierarchyResourcePermissionsGridResourceLabel").value = argument.item.label;

                document.getElementById("HierarchyResourcePermissionsGridResourceTypeName").value = argument.item.resourceTypeName;

            }

        });


        var autoCompleteUserName = new ej.dropdowns.AutoComplete({

            dataSource: window.dataManagerUser,

            fields: { "text": "value", "key": "id" },

            width: "100%",

            autoFill: false,

            emptyResultText: window.noResultMessage,

            value: args.rowData.Value,

            select: function (argument) {

                console.log(argument.itemData.name);

                document.getElementById("HierarchyResourcePermissionsGridUserName").value = argument.itemData.name;

                document.getElementById("HierarchyResourcePermissionsGridRoleName").value = argument.itemData.role;

                document.getElementById("HierarchyResourcePermissionsGridOrgChartName").value = argument.itemData.orgchart;

            }

        });


        autoCompleteResourceLabel.appendTo("#HierarchyResourcePermissionsGridResourceLabel");

        autoCompleteUserName.appendTo("#HierarchyResourcePermissionsGridUserName");



2 Replies

RR Rajapandi Ravi Syncfusion Team October 29, 2021 05:52 AM UTC

Hi Dan, 

Greetings from Syncfusion support 

Currently we are checking your query with your shared information, and we will update you the details on Monday, 1st Nov 2021. Until then we appreciate your patience. 

Rajapandi R 



JC Joseph Christ Nithin Issack Syncfusion Team November 2, 2021 08:41 AM UTC

Hi Dan, 

  Thanks for your patience. 

  Based on your query, when you click on the add button and then you click the cancel button you are facing a script error. By default in EJ2 Grid, when you click on the add button followed by the cancel button, the add action will be canceled and no request will be sent to the server. 

  On inspecting the code example provided, we can see that you have applied some customization in the `actionComplete` event when the `requestType` is beginEdit or add. Please explain the exact requirement of adding the customization in detail, so that we will be able to proceed to provide a better solution ASAP. 

Please get back to us for further details. 

Regards, 
Joseph I. 


Loader.
Up arrow icon