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

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

Thread ID:

Created:

Updated:

Platform:

Replies:

141054 Nov 20,2018 05:16 PM UTC Nov 22,2018 08:43 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Juan Cruz
Asked On November 20, 2018 05:16 PM UTC

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.

Vignesh Natarajan [Syncfusion]
Replied On 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 


Juan Cruz
Replied On 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

Vignesh Natarajan [Syncfusion]
Replied On 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 


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