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.
Unfortunately, activation email could not send to your email. Please try again.

ASP.NET MVC 5 query for Dialog Box Template.

Thread ID:

Created:

Updated:

Platform:

Replies:

123196 Feb 25,2016 04:14 AM Apr 14,2016 01:20 AM ASP.NET MVC 3
loading
Tags: Grid
himanshu ratnakar
Asked On February 25, 2016 04:14 AM

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 

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On February 26, 2016 01:16 AM

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: http://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.

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

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



Regards,
Seeni Sakthi Kumar S.

Mahindra Morar
Replied On April 13, 2016 03:26 AM

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

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On April 14, 2016 01:20 AM

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: http://www.syncfusion.com/downloads/support/forum/123196/ze/DialogEditTemplate1536783885.zip

Regards,
Seeni Sakthi Kumar S.

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.

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.

;