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

ASP.NET MVC 5 query for Dialog Box Template.

Hello,
         I am using Syncfusion for my personal use and it is a nice product. 

I am not able to use the Grid as I require CRUD functionality using URL adapter (AdaptorType.UrlAdaptor) and DialogTemplate (EditMode.DialogTemplate) with checking for Duplicate value before adding or editing a record in Database

Please provide a sample example meeting this requirement.


Thanks 
Himanshu 

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team February 26, 2016 06:16 AM UTC

Hi Himanshu,

We have prepared a sample with your requirement “To check an already existing data in the datasource” that can be downloaded from the following location.

Sample: https://www.syncfusion.com/downloads/support/forum/123196/ze/DialogEditTemplate1848795145

In the server-side, while inserting a record we can check whether the data is already existing or not in the dataSource. In our case, OrderID is primary key. So we have used them to check the data duplication. Refer to the code example.


@(Html.EJ().Grid<MvcApplication66.OrdersView>("FlatGrid")

        .Datasource(ds => ds.URL("/Home/DataSource/").UpdateURL("/Home/Update").InsertURL("/Home/Insert").Adaptor(AdaptorType.UrlAdaptor))

        .AllowPaging()

        .ToolbarSettings(tool => tool.ShowToolbar().ToolbarItems(tools => {

           . . . . .

        }))

        .EditSettings(edit => edit.AllowEditing().AllowAdding().AllowDeleting().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template"))

  .. . . . ..

        .ClientSideEvents(events => events.ActionFailure("failed"))
)

namespace MvcApplication66.Controllers

{

    public class HomeController : Controller

    {

               . . . . .

        public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)

        {

             . . . . ..

        }

        public ActionResult Insert(EditableOrder value)

        {

            var obj = OrderRepository.GetAllRecords().Where(ord => ord.OrderID == value.OrderID).SingleOrDefault();

            if(obj != null)//Check already exisiting

                throw new InvalidOperationException("OrderID already existis");//Exception thrown if exisiting

            OrderRepository.Add(value);

            var data = OrderRepository.GetAllRecords();

            return Json(value, JsonRequestBehavior.AllowGet);

        }

            . . . ..

    }
}

    function failed(args) {//after exception from the server, we can alert the client-side using actionFailure

        //args.error provides the details of exception

        window.alert("OrderID already existis");

        $("#FlatGrid").ejWaitingPopup("hide")
    }


To inform the client-side about the server-side failure, we have used the actionFailure event of Grid. Refer to the following Help Document.

https://help.syncfusion.com/api/js/ejgrid#events:actionfailure

In the actionFailure event’s parameter, we can get the following information.



Regards,
Seeni Sakthi Kumar S.


MM Mahindra Morar April 13, 2016 07:26 AM UTC

Hi,
Would it be possible to send an error message from the controller method  public ActionResult Insert(EditableOrder value)  to the function failed(args) 

Thanks


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team April 14, 2016 05:20 AM UTC

Hi Himansu,

Query: Would it be possible to send an error message from the controller method  public ActionResult Insert(EditableOrder value)  to the function failed(args)

Yes, we can get the server-side exception/error message in the actionFailure event. The parameter (args.error.responseText) get the error message from the server-side. Refer to the following code example

@(Html.EJ().Grid<MvcApplication66.OrdersView>("FlatGrid")

        .Datasource(ds => ds.URL("/Home/DataSource/").UpdateURL("/Home/Update").InsertURL("/Home/Insert").Adaptor(AdaptorType.UrlAdaptor))

        .AllowPaging()

              . . . . . . .

        .ClientSideEvents(events => events.ActionFailure("failed").ActionComplete("complete"))

)

<script>

    function failed(args) {

        //args.error provides the details of exception

        //after exception from the server, we can alert the client-side using actionFailure

        window.alert(($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text()));

        $("#FlatGrid").ejWaitingPopup("hide")

    }

   . . . .

</script>

        public ActionResult Insert(EditableOrder value)

        {

            var obj = OrderRepository.GetAllRecords().Where(ord => ord.OrderID == value.OrderID).SingleOrDefault();

            if(obj != null)

                throw new InvalidOperationException("OrderID already existis");//Exception thrown

            OrderRepository.Add(value);

            var data = OrderRepository.GetAllRecords();

            return Json(value, JsonRequestBehavior.AllowGet);
        }


We have also modified the sample that can be downloaded from the following location.

Sample: https://www.syncfusion.com/downloads/support/forum/123196/ze/DialogEditTemplate1536783885.zip

Regards,
Seeni Sakthi Kumar S.

Loader.
Live Chat Icon For mobile
Up arrow icon