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.
Syncfusion Feedback

Grid with CRUD functionality and NHIBERNATE: added records require page refresh in order to be shown

Thread ID:

Created:

Updated:

Platform:

Replies:

120076 Aug 28,2015 03:52 AM Feb 9,2016 11:03 PM ASP.NET MVC 9
loading
Tags: Grid
Carlo
Asked On August 28, 2015 03:52 AM

Greetings. I'm using the latest release of Syncfusion ASP.NET MVC (13.2.0.34). I've been following this how to 

http://help.syncfusion.com/ug/aspnetmvc/Documents/usenhibernatewithgrid.htm

to implement a grid with CRUD functionalities which interacts with NHIBERNATE, but I'm experiencing the following issue: adding a new record require the page to be manually refreshed for it to be shown in the grid. Don't know if this is relevant, but, instead, editing a record shows changes immediately. If you're unable to reproduce the issue I'm experiencing, may you provide a working example with CRUD functionality which doesn't present this issue? (even without NHIBERNATE, since I suppose that it doesn't really matter in this context)

Thanks for your time.

Carlo
Replied On August 28, 2015 04:37 AM

For your convenience, I've prepared and example which replicates the issue (even without NHIBERNATE, as I suspected). I've not been able to include the package folder because the zip would have become too big. I hope you can figure out the missing dependancies. I'm using the last syncfusion version, 13.2.0.34. Just click on the "Grid" menu entry on the top right of the home page to access the syncfusion CRUD grid which presents the issue.



Attachment: NewRecordsRequireRefreshToBeShown_3b8293b1.7z

Carlo
Replied On August 31, 2015 04:44 AM

Just updating this thread with some extra information: this problem is happening with any possible CRUD setup provided on your documentation:

URL ADAPTOR: http://help.syncfusion.com/ug/aspnetmvc/Documents/urladaptor.htm
REMOTE SAVE ADAPTOR: http://help.syncfusion.com/ug/aspnetmvc/Documents/remotesaveadaptor.htm
NHIBERNATE SPECIFIC HOWTO CRUD: http://help.syncfusion.com/ug/aspnetmvc/Documents/usenhibernatewithgrid.htm

In any of the aforementioned situations, adding a new record required a page refresh for it to be displayed, even if the numer in the bottom right, which contains the amount of records, is correctly updated. Any hint about why is this happening?

Ragavee U S [Syncfusion]
Replied On August 31, 2015 05:12 AM

Hi Carlo,

We have analyzed the reported issue and the sample that you have shared with us.

From your sample, we found that you have returned the JSON data from server on Insert, Update and Delete request in “{result,count}” format.

Based on our current implementation, we need to return the JSON data as it is from the server to the client after handling the CRUD operations at the server side instead of passing it in “{result,count}” format. We will modify our following online documentation accordingly with updated information as early as possible.

http://help.syncfusion.com/ug/aspnetmvc/Documents/usenhibernatewithgrid.htm

Please refer to the following online links for more information on the response Type.

Online Sample link: http://mvc.syncfusion.com/demos/web/grid/normalediting

Online Documentation link: http://help.syncfusion.com/ug/aspnetmvc/index.html#!Documents/remotedata2.htm

We have modified your sample with the above solution and the same can be downloaded from the following location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/120076/ze/NewRecordsRequireRefreshToBeShown_Modified639264429

Regards
Ragavee U S

Carlo
Replied On February 2, 2016 12:32 PM

Greetings. One further point about using nhibernate with grid. I've always been using the methods you suggested on the controller:

public ActionResult PerformUpdate(int key, EmployeeMap value)
public ActionResult PerformInsert(string action, EmployeeMap value)

Now, what if one of these operations (insert or update) throws an exception (not all validation can be done client side). How can I show the exception message to the user (ideally, through an ejDialog)? There should be a way to return a Json with status = "Error" and Data="error_message", like I do with post request/responses. Thanks a lot!

Ragavee U S [Syncfusion]
Replied On February 3, 2016 03:40 AM

Hi Carlo,

By default we have the actionFailure event to show the server side exception. Please refer to the following Knowledge base link.

https://www.syncfusion.com/kb/5170/how-to-display-custom-error-message-on-ajax-action-failture

Please refer to the online api reference documentation,

http://help.syncfusion.com/js/api/ejgrid#event:actionFailure

These are the ways to handle the exception. If you want some generic exception handling techniques, please refer the following online link location:

http://www.codeproject.com/Articles/850062/Exception-handling-in-ASP-NET-MVC-methods-explaine

Regards,
Ragavee U S.

Carlo
Replied On February 4, 2016 04:59 AM

Thanks for the reply. I've tried to investigate the actionFailure event that you pointed out, in order to make it work with the adaptor that I'm using, which is a "RemoteSaveAdaptor":

@(Html.EJ().Grid<object>("Grid")
        .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource)
            .UpdateURL("AnagraficaMacchine/PerformUpdate")
            .InsertURL("AnagraficaMacchine/PerformInsert")
            .Adaptor(AdaptorType.RemoteSaveAdaptor))...

the problem is that methods "PerformUpdate" and "PerformInsert" you suggested me don't ever return an error message: they only return the item which has been added/updated:

public ActionResult PerformInsert(string action, EmployeeMap value)

        {

            using (ISession session = AppSession.OpenSession())

            {

                using (ITransaction transaction = session.BeginTransaction())

                {

                    session.Save(value);

                    transaction.Commit();

                }

                list = session.Query<EmployeeMap>().ToList();

            }

            return Json(new { result = value, count = list.Count() }, JsonRequestBehavior.AllowGet);

        }



        //PERFORM UPDATE

        public ActionResult PerformUpdate(int key, EmployeeMap value)

        {

            using (ISession session = AppSession.OpenSession())

            {

                var employeetoUpdate = session.Get<EmployeeMap>(key);



                employeetoUpdate.Designation = value.Designation;

                employeetoUpdate.FirstName = value.FirstName;

                employeetoUpdate.LastName = value.LastName;



                using (ITransaction transaction = session.BeginTransaction())

                {

                    session.Save(employeetoUpdate);

                    transaction.Commit();

                }

                list = session.Query<EmployeeMap>().ToList();

            }



            return Json(new { result = value, count = list.Count() }, JsonRequestBehavior.AllowGet);

        }
I modified the PerformUpdate method so that it returns the following:
return Json(new { Status = "error", Data = "not working!" });
Unfortunately, the event "actionFailure" wasn't even raised..so, my requirement is the following:
How should I modify PerformUpdate and PerformInsert methods (considering that I'm using RemoteSaveAdaptor) in order to correctly trigger ActionFailure() on insert and update actions when the backend raises an exception (because some input data isn't valid)? Thanks a lot for the kind help!

Ragavee U S [Syncfusion]
Replied On February 5, 2016 06:25 AM

Hi Carlo,

The actionFailure event will be triggered once an exception occurs at server side data/CRUD operations. If you want to trigger the actionFailure event when validation fails at server side, we suggest you to manually throw the exception at the server side.

In actionFailure event, we can get the exception message and display it using event argument. Please find the code example for more reference.

//Perform update

        public ActionResult PerformUpdate(OrderTable value)

        {

            if(value.OrderID>300) // validation get failed

                throw new Exception("Data is not valid"); // Exception message

            return Json(value, JsonRequestBehavior.AllowGet);

        }

Javascript

//actionFailure event of the Grid

function failure(args) {

        alert(args.error.responseText); //get the exception message

    }


We have prepared a simple sample, which can be downloaded from the below location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/120076/ze/sampleapplication1283148727

Regards,

Regards,
Ragavee U S.

Carlo
Replied On February 9, 2016 12:23 PM

Thanks, I got it now: at first, I didn't understood that I had to let the exception occur instead of catching it in the controller. Now it works as intended. Requirement achieved =) Thanks a lot for your outstanding support!

Ragavee U S [Syncfusion]
Replied On February 9, 2016 11:03 PM

Hi Carlo,

Thanks for your update.

We are happy that your requirement is achieved.

Regards,
Ragavee U 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.

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

;