Event actionFailure not fired on update

Hello, 
I have problem with actionFailure event, it's not fireing when update operation fails but grid is in stucked on infinite loading.
When I do insert and it fails event works well, I have problem only with update operation. Can you help me? 


Index.cshtml:

@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Products</h1>

<ejs-grid id="Grid" actionFailure="failure" allowPaging="true" allowSorting="true" allowMultiSorting="true" allowGrouping="true" toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Update", "Cancel", "Search" })">
    <e-data-manager url="/Product/UrlDataSource" insertUrl="/Product/Insert" updateUrl="/Product/Update" removeUrl="/Product/Delete" adaptor="UrlAdaptor"/>
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal" newRowPosition="Bottom"/>
    <e-grid-pagesettings pageSizes="true"/>

    <e-grid-columns>
        <e-grid-column field="Id" headerText="ID" isPrimaryKey="true" isIdentity="true"/>
        <e-grid-column field="Name" headerText="Name" validationRules="@(new { required=true })"/>
        <e-grid-column field="Description" headerText="Description"/>
        <e-grid-column field="Suspended" headerText="Suspended" editType="booleanedit" displayAsCheckBox="true"/>
        <e-grid-column field="CreationDate" headerText="Creation Date" isIdentity="true" customFormat="@(new { type = "date", format = "dd/MM/yyyy HH:MM:ss" })"/>
    </e-grid-columns>
</ejs-grid>

<script>
    function failure(args) {
        var span = document.createElement('span');
        this.element.parentNode.insertBefore(span, this.element);
        span.style.color = '#FF0000'
        span.innerHTML = args.error[0].error.responseText;
    }
</script>


Controller:

     public async Task<IActionResult> Insert([FromBody] CRUDModel<ApplicationProduct> crud)
        {
            var product = new ApplicationProduct
            {
                Name = crud.Value.Name,
                Description = crud.Value.Description,
                Suspended = crud.Value.Suspended
            };

            if (await dbContext.Products.FirstOrDefaultAsync(p => p.Name == product.Name) != null)
            {
                return StatusCode(400, "Product with this name already exists!");
            }

            await dbContext.AddAsync(product);
            await dbContext.SaveChangesAsync();

            return Json(crud.Value);
        }

        public async Task<IActionResult> Update([FromBody] CRUDModel<ApplicationProduct> crud)
        {
            var product = await dbContext.Products.FindAsync(crud.Value.Id);
            var existingProduct = await dbContext.Products.FirstOrDefaultAsync(p => p.Name == crud.Value.Name);

            if (existingProduct != null && existingProduct.Id != product.Id)
            {
                return StatusCode(400, "Product with this name already exists!");
            }

            product.Name = crud.Value.Name;
            product.Description = crud.Value.Description;
            product.Suspended = crud.Value.Suspended;

            await dbContext.SaveChangesAsync();

            return Json(crud.Value);
        }


3 Replies 1 reply marked as answer

AG Ajith Govarthan Syncfusion Team September 10, 2020 02:09 PM UTC

Hi Michal 

Thanks for contacting Syncfusion support. 

Based on the attached code example we have prepared the sample but we did not face any issues in the prepared sample. In that we have used  inline Editing and also handled the exceptions with action Failure event. 

For your convenience we have attached the sample so please refer the sample for your reference. 

Code Example: 
Index.cshtml 

<ejs-grid id="Grid" allowPaging="true" allowSorting="true" actionFailure="actionFailure" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings> 
    <e-data-manager url="/Home/TelecomDataSource" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" adaptor="UrlAdaptor"></e-data-manager> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" width="120" ></e-grid-column> 
        <e-grid-column field="OrderDate" headerText="Freight" type="date" textAlign="Right" format="yMd" editType="datepickeredit" width="120"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="City" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    function actionFailure(args) { 
        var errorMessage = args[0].error.responseText.split("Exception:")[1].split("</div>")[0]; 
        alert(errorMessage); 
    } 
</script> 


If you still face the issue then please share the below details to validate further on your requirement. 
 
1.                   If possible please try to reproduce the issue in the attached sample. 

2.                   Share the screenshot or video demonstration of the issue. 
 
3.                   Share the Syncfusion package version. 

Regards, 
Ajith G. 



UN Unknown Syncfusion Team September 10, 2020 09:03 PM UTC

Thanks for answer, 
I found the problem , my failure function in js causeing the bug. Parameter args is different when update or insert fails.


To get response text when update failed I have to use 'args[0].error.responseText' but when instert 'args.error[0].error.responseText'.


    function actionFailure(args) {
        try {
            var text = args[0].error.responseText;
            console.log("OK - args[0].error.responseText");
        }
        catch (error) {
            console.log("Error - args[0].error.responseText");
        }

        try {
            var text = args.error[0].error.responseText;
            console.log("OK - args.error[0].error.responseText");
        }
        catch (error) {
            console.log("Error - args.error[0].error.responseText");
        }
    }

Shouldn't args object be the same at all types of errors or what function to log errors should I use?


AG Ajith Govarthan Syncfusion Team September 17, 2020 12:50 PM UTC

Hi Michal, 

Thanks for your patience. 
      
We have validated the provided information and we are able to reproduce the reported problem. We have confirmed it as a bug and logged the defect report “Arguments structure mismatches in actionFailure event for update and insert exceptions”. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming  weekly release which is expected to be rolled out on 30th September, 2020. 
    
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    
    
    
Until then we appreciate your patience.     

Regards, 
Ajith G. 


Marked as answer
Loader.
Up arrow icon