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

Show Dialog box to display CRUD operation error.

Hi,
Do you have any examples on how to display the error returned from the controller when using the Datamanager - UrlAdaptor inside a Dialog control?

My sample code looks like this in the controller, and I want to display the value in the variable "errorMsg" inside a dialog control in the view.

 public async Task<ActionResult> Update([FromBody]CRUDModel<mdCurrency> value)
        {

            var url = string.Format("{0}/{1}/{2}", URI_RESOURCE, value.Key, value.Value.Lockstamp);
            var response = await PutWSObjectAsync<mdCurrency, mdCurrencyResponse>(value.Value, url);

            var errorMsg = MessageFormatter.FormatCrudResults(response.CrudResults);    
       
            return null;
        }  

Thanks


1 Reply

MS Mani Sankar Durai Syncfusion Team October 10, 2017 12:13 PM UTC

Hi Mahindra, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and based on your requirement we have prepared a sample that can be downloaded from the below link. 
In this sample we have thrown the error message from server side (controller) and shown the error message in dialog box.  This has been achieved using actionFailure event in grid.  
Refer the code example 
<ej-dialog id="ErrorList" title="Error" show-on-init="false"  close="onDialogClose"></ej-dialog> 
    <ej-grid id="FlatGrid" allow-paging="true" action-failure="failure"> 
        <e-filter-settings filter-type="Excel"></e-filter-settings> 
        <e-datamanager url="/Home/DataSource" update-url="/Home/NormalUpdate" insert-url="/Home/NormalInsert" remove-url="/Home/NormalDelete" adaptor="UrlAdaptor"></e-datamanager> 
        ... 
        <e-columns> 
            
        </e-columns> 
    </ej-grid> 
    <script> 
        function failure(args) { 
            var error = $(args.error.responseText).eq(9).text();  //get the error message from server side. 
            str += "<tr><td>" + error + "</td></tr>"; 
            $('#ErrorList').html(""); 
            $('#ErrorList').html("<table>" + str + "</table>"); 
            $('#ErrorList').ejDialog("open"); 
        } 
    </script> 
 
[HomeController.cs] 
public ActionResult NormalUpdate([FromBody]CRUDModel<Order> myObject) 
        { 
             
            ... 
            if(myObject.Value.EmployeeID > 9) 
            throw new Exception("EmployeeID must be above 1000"); 
            ... 
        } 
        public ActionResult NormalInsert([FromBody]CRUDModel<Order> value) 
        { 
            if (value.Value.OrderID > 10000) 
                throw new Exception("OrderID must be above 1000"); 
... 
        } 

From the above code example after the exception thrown from the server side the error has been retrieved using actionFailure event in grid. In the actionFailure event we have set the error message to the dialog html and open the dialog using dialog open method.  
Note: Initially we have set the dialog not visible using show-on-init property as false. 
Refer the documentation link. 

Refer the Kb link 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Live Chat Icon For mobile
Up arrow icon