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

Scheduler - Server side validation

Thread ID:

Created:

Updated:

Platform:

Replies:

148916 Nov 7,2019 05:49 PM UTC Nov 8,2019 02:01 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: Scheduler
Brian Rutter
Asked On November 7, 2019 05:49 PM UTC

In the Scheduler, how do you do Server Side validation and return a message to the user before closing the edit dialog?

An example: If we need to do conflict checking, or date checking on the server side, how do we show this in a validation summary?

Thanks

Hareesh Balasubramanian [Syncfusion]
Replied On November 8, 2019 02:01 PM UTC

Hi Brain, 
 
Greetings from Syncfusion Support. 
 
We have prepared below sample to achieve server side validation by using actionBeginevent of our scheduler. Please refer it. 
 
    function onActionBegin(args) { 
        if (args.requestType == "eventCreate") { 
            // Server validation post 
            var UserData = args.data[0]; 
            $.ajax({ 
                url: '/Home/CRUDData/', 
                data: JSON.stringify(UserData), 
                type: 'POST', 
                async: false, 
                traditional: true, 
                contentType: 'application/json', 
                success: function (data) { 
                    if (data.status && data.status != "") { 
                        if (data.status != "Validation Passed") { 
                            // If server validation fail we prevent the appointment save in db by using args.cancel = true 
                            args.cancel = true; 
                            if (!ej.base.isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
                                var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
                                schObj.uiStateValues.isBlock = true; 
                            } 
                        } 
                        // Show the message in dialog 
                        dlgObj.content = data.status; 
                        dlgObj.show(); 
 
                    } 
                }, 
                failure: function (data) { 
                    alert("Failure occurred") 
                }, 
                error: function (data) { 
                    alert("Error Occurred") 
                } 
            }); 
        } 
    } 
 
    function onActionComplete(args) { 
        if (!ej.base.isNullOrUndefined(document.querySelector('.e-schedule-dialog'))) { 
            var diaObj = document.querySelector('.e-schedule-dialog').ej2_instances[0]; 
            var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
            schObj.uiStateValues.isBlock = false; 
            diaObj.hide(); 
        } 
    } 
 
Server: 
      [HttpPost] 
        public ActionResult CRUDData([FromBody]ScheduleEvent model) 
        { 
            var status = ""; 
            if (model != null) 
            { 
                var data = _context.ScheduleEvents.Where(app => (app.Subject == model.Subject)).ToList(); 
                if (data.Count > 0) 
                { 
                    status = "Please Save the appointment with differnt Subject. The provided subject already exist in db"; 
                } 
                else 
                { 
                    status = "Validation Passed"; 
                } 
            } 
            else 
            { 
                status = "failure"; 
            } 
            return Json(new { status = status }); 
        } 
 
Kindly try the above samples, if you have any concerns please revert us back for further assistance. 
 
Regards, 
Hareesh 
 


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