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.
Unfortunately, activation email could not send to your email. Please try again.

Show Dialog box to display CRUD operation error.

Thread ID:

Created:

Updated:

Platform:

Replies:

133089 Oct 9,2017 04:36 AM Oct 10,2017 08:13 AM ASP.NET Core 1
loading
Tags: Grid
Mahindra Morar
Asked On October 9, 2017 04:36 AM

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


Mani Sankar Durai [Syncfusion]
Replied On October 10, 2017 08:13 AM

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;