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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Send an error message to the user inside the CrudData method

Thread ID:

Created:

Updated:

Platform:

Replies:

147473 Sep 11,2019 08:45 PM UTC Sep 19,2019 04:33 AM UTC ASP.NET Core - EJ 2 8
loading
Tags: Scheduler
Gregory Perozzo
Asked On September 11, 2019 08:45 PM UTC

Hello,

I need to return a message to the user to show some info or tell something is wrong inside the CRUD method.

I already asked this inside another thread CRUD operations not working.

Back there, Karthigeyan asked me to try ActionFailure event.

I managed to make it by returning a status 400 bad request, but I think this is not the right way to do it.



And in the Scheduler:



function onActionFailure(args) {

            console.log(args);
            
            //var scheduleObj = document.getElementById('schedule').ej2_instances[0];
            //var span = document.createElement('span');
            //scheduleObj.element.parentNode.insertBefore(span, scheduleObj.element);
            //span.style.color = '#FF0000';
            //span.innerHTML = 'Server exception: 404 Not found';
}

How can I return a proper error message and show it to the user without using a BadRequest status?

Thank you very much!

Karthigeyan Krishnamurthi [Syncfusion]
Replied On September 12, 2019 09:08 AM UTC

Hi Gregory 
  
Syncfusion greetigns. 
 
In ActionFailure event, we can retrieve the failure message through args.error[0].error and for the same below sample is prepared. 
 
function onActionFailure(args) {
console.log(args.error[0].error);
alert(args.error[0].error.responseURL + " "+ args.error[0].error.status + ' (' + args.error[0].error.statusText + ")");
}
 
 
Regards, 
Karthi 
 


Gregory Perozzo
Replied On September 12, 2019 01:51 PM UTC

Hello Karthigeyan,

Thank you very much for your help and for the project provided!

Have a nice day!

Gregory Perozzo
Replied On September 12, 2019 07:46 PM UTC

Hello again Karthigeyan,

How can I send a message to the onActionComplete(args) event from the Controller?

I need to send a specific message after the event creation to the user and it has to be sent from the Controller.

Thank you!

Hareesh Balasubramanian [Syncfusion]
Replied On September 13, 2019 01:30 PM UTC

Hi Gregory, 

Thanks for your update. 

Based on your requirement we have prepared a sample, which can be downloaded from the following link, 

Kindly try the above sample, if you have any concerns please revert us back for further assistance. 

Regards, 
Hareesh 


Gregory Perozzo
Replied On September 16, 2019 07:23 PM UTC

Hello Hareesh,

Thank you very much for your answer and sample.

Unfortunately, in the sample, the ViewBag.Message is set before the event creation, in the Index() method.

To use this inside the CRUD method (UpdateData) I must refresh the page, and I didn't want to do that.

I need to return a success message to the user inside the UpdateData (without refreshing the page) method because my API returns a status message that I need to inform the user.

I tried to add a new property 'Message' to the ScheduleEvent object and set my message on this property and then return the object to the scheduler again, but I didn't succeded.

ScheduleEvent class:

public class ScheduleEvent
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public string Date { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string StartTimezone { get; set; }
        public string EndTimezone { get; set; }
        public bool IsAllDay { get; set; }
        public string Status { get; set; }
        public string Workload { get; set; }
        public string Student { get; set; }
        public string Teacher { get; set; }
        public string Vehicle { get; set; }
        public string Color { get; set; }
        public bool IsReadonly { get; set; }
        public string Message { get; set; }
    }

UpdateData method:



When I catch the return in the onActionComplete(args) method, the 'Message' property comes empty.

Do you have another solution to this? Something like onActionFailure(args) method where I can pass a message to the response?


Hareesh Balasubramanian [Syncfusion]
Replied On September 17, 2019 05:16 PM UTC

Hi Gregory, 

Thanks for your update. 

Based on the requirement, we have modified our previous sample using CustomAdaptor and sample can be downloaded from the below link, 

<ejs-schedule id="schedule" width="100%" created="onCreate" height="550"> 
</ejs-schedule> 

<script type="text/javascript"> 
    function onCreate() { 
        class CustomAdaptor extends ej.data.UrlAdaptor { 
            processResponse() { 
                // calling base class processResponse function 
                var original = super.processResponse.apply(this, arguments); 
                if (arguments[4].url === "Home/UpdateData" && arguments[3].response !== "") { 
                    alert(arguments[3].response); 
               
                return original; 
           
       
        var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
        schObj.eventSettings.dataSource = new ej.data.DataManager({ 
            url: "/Home/LoadData", crudUrl: "Home/UpdateData", 
            adaptor: new CustomAdaptor(), crossDomain: true 
        }); 
   
</script> 
  
Kindly try the above sample, if you have any concerns please revert us back for further assistance. 

Regards, 
Hareesh 



Gregory Perozzo
Replied On September 18, 2019 06:26 PM UTC

Hareesh,

That's exactly what I need!

Just tested and it worked perfectly!

You are awesome, SyncFusion is awesome, made my day.

Thank you very much for your support and patience!

Karthigeyan Krishnamurthi [Syncfusion]
Replied On September 19, 2019 04:33 AM UTC

 
We are happy that our solution fulfilled your requirement. 
 
Regards, 
Karthi 
 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon