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

Custom Success/Info/Error Messages

Hello,

iam using the Grid with CRUDURL for Editing. How to alert the Client with custom send Messages from the Controller? How to pass a Message to a JS-Function from the Controller?

".ClientSideEvents(cse=>cse.EndEdit("alertOK"))"

function alertOK(args, msg) {
            toastr.success(msg);
        }

C#-Controller:

 public ActionResult CrudUpdate(Mitarbeiter value, string action)
        {
            if (action== "update")
            {
                cont.Entry(value).State = EntityState.Modified;
                cont.SaveChanges();
                return Json(????):
            }


1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team June 7, 2016 06:16 PM UTC

Hi Arthur, 

Thank you for contacting Syncfusion support. 

To pass a message to the client from the controller, use the custom adaptor in the grid. In the custom adaptor, the processResponse has to be overridden to process the data from the server. We have extended processResponse method of the ej.UrlAdaptor and in the extended method we display the alert message. 
 
The custom adaptor has been assigned in the grid Load event. 
 
Find the code example and sample: 
 
 
@(Html.EJ().Grid<object>("Grid") 
         .Datasource(ds => ds.URL("/Home/DataSource").Adaptor("UrlAdaptor").CrudURL("/Home/Update")) 
        .EditSettings(edit => { edit.AllowEditing().AllowAdding().AllowDeleting(); }) 
         .AllowPaging() 
        .ToolbarSettings(toolbar => 
            { 
                toolbar.ShowToolbar().ToolbarItems(items => 
                { 
                    items.AddTool(ToolBarItems.Add); 
                    items.AddTool(ToolBarItems.Edit); 
                    items.AddTool(ToolBarItems.Delete); 
                    items.AddTool(ToolBarItems.Update); 
                    items.AddTool(ToolBarItems.Cancel); 
                }); 
            }) 
         .Columns(col => 
        { 
-------------------------------------------- 
        }) 
        .ClientSideEvents(eve => { eve.Load("load"); }) 
) 
 
<script type="text/javascript"> 
 
    function load(args) { 
        this.model.dataSource.adaptor = new customAdaptor(); 
    } 
        var customAdaptor = new ej.UrlAdaptor().extend({ 
 
            processResponse: function (data, ds, query, xhr, request, changes) {               
                if (data.success != undefined) 
                    alert(data.success); 
                var obj = ej.UrlAdaptor.prototype.processResponse(data, ds, query, xhr, request, changes); 
                return obj;                    
            }, 
        }); 
</script> 
 
------------------------------------------------------------------------ 
public ActionResult Update(EditableOrder value) 
        { 
            OrderRepository.Update(value); 
            var data = OrderRepository.GetAllRecords(); 
            if (value.Freight != null) 
                return Json(new { result = data, success = "success" }, JsonRequestBehavior.AllowGet); 
            else 
                return Json(new { result = data, success = "failure" }, JsonRequestBehavior.AllowGet); 
        } 
 
 
 
Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Up arrow icon