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
close icon

How to tell the client that the operation of crud failed on the server side?

Hi, I am using the grid control in mvc with URLAdaptor, and I would like to know how to inform to the client side if an error occurred on the server side.
I have this code in a view:

@(Html.EJ().Grid<object>("Test")
    .Datasource(ds=>ds.URL(Url.Action("Data", "GridTest1", null, Request.Url.Scheme))
        .InsertURL(Url.Action("Create", "GridTest1", null, Request.Url.Scheme))
        .UpdateURL(Url.Action("Update", "GridTest1", null, Request.Url.Scheme))
        .RemoveURL(Url.Action("Delete", "GridTest1", null, Request.Url.Scheme))
        .Adaptor(AdaptorType.UrlAdaptor))
    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().RowPosition(RowPosition.Bottom).EditMode(EditMode.ExternalForm); })
    .Locale("es-ES")
    .ToolbarSettings(toolbar =>
    {
        toolbar.ShowToolbar().ToolbarItems(item =>
        {
            item.AddTool(ToolBarItems.Add);
            item.AddTool(ToolBarItems.Cancel);
            item.AddTool(ToolBarItems.Delete);
            item.AddTool(ToolBarItems.Edit);
            item.AddTool(ToolBarItems.Update);
            item.AddTool(ToolBarItems.ExcelExport);
            item.AddTool(ToolBarItems.PdfExport);
            item.AddTool(ToolBarItems.WordExport);
        });
    })
    .AllowPaging()
              .AllowReordering()
              .IsResponsive()
              .PageSettings(p => { p.PageSize(10); })
              .AllowResizeToFit()
              .AllowSorting()
    .Columns(col =>
    {
        col.Field("MarcaId").HeaderText("ID").IsIdentity(true).IsPrimaryKey(true).Add();
        col.Field("Marca").ValidationRules(v => v.AddRule("required", true).AddRule("messages", "{required:'Campo obligatorio'}")).Add();
        col.Field("FechaAlta").AllowEditing(false).Add();
        col.Field("FechaActividad").AllowEditing(false).Add();
        col.Field("Status").HeaderText("Estatus").AllowEditing(false).Add();
    })
    .ClientSideEvents(e=> { e.ActionComplete("complete").ActionBegin("begin").EndEdit("endEdit").EndAdd("endAdd").ActionFailure("fail"); })
    )

<script type="text/javascript">
    function begin(args) {
        if (args.requestType == "save") {
            this.element.ejWaitingPopup("show");
        }
    }

    function endEdit(args) {
        this.element.ejWaitingPopup("hide");
    }

    function endAdd(args) {
        this.element.ejWaitingPopup("hide");
    }

    function complete(args) {
        console.log(args);
        if (args.requestType == "cancel")
            this.element.ejWaitingPopup("hide");
        if (args.requestType == "save")
            this.refreshContent();
    }

    function fail(args) {
        console.log(args);
        this.cancelEdit();
        alert("Servicio no disponible");
    }
</script>

and in the server side:
public ActionResult Create(REPEQPCAT_MARCARECURSOS value)
        {
            try
            {                
                context.REPEQPCAT_MARCARECURSOS.Add(value);
                context.SaveChanges();
                return Json(value, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }
I hope you can help me
first of all, Thanks.

3 Replies

VN Vignesh Natarajan Syncfusion Team November 21, 2018 05:07 AM UTC

Hi Juan, 


Thanks for using Syncfusion products. 


From your query, we understand that you need to alert the user that CRUD operation has been failed in server side. We have already discussed this topic in our knowledge base section. Kindly refer the below link for the knowledge base document. 




Please get back to us if you have further queries.   


Regards, 
Vignesh Natarajan 



JC Juan Cruz November 21, 2018 06:09 PM UTC

Ok, I already read the article and the only question I have left is that it can be used with AdaptorType.URLAdaptor or if I should change to AdaptorType.RemoteSaveAdaptor


VN Vignesh Natarajan Syncfusion Team November 22, 2018 08:43 AM UTC

Hi Juan, 
 
Thanks for the update. 
 
Query: “is that it can be used with AdaptorType.URLAdaptor or if I should change to AdaptorType.RemoteSaveAdaptor” 
 
Yes, you can use the solution provided in the knowledge base document while using URLAdaptor. For your convenience we have prepared a sample suing URL adaptor and implemented that solution. Kindly download the sample from below link 
 
 
 
Please get back to us of you have any queries. 
 
Regards, 
Vignesh Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon