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

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

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.

9 Replies

CA Carlo August 28, 2015 08:37 AM UTC

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


CA Carlo August 31, 2015 08:44 AM UTC

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?


RU Ragavee U S Syncfusion Team August 31, 2015 09:12 AM UTC

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


CA Carlo February 2, 2016 05:32 PM UTC

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!


RU Ragavee U S Syncfusion Team February 3, 2016 08:40 AM UTC

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.


CA Carlo February 4, 2016 09:59 AM UTC

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!


RU Ragavee U S Syncfusion Team February 5, 2016 11:25 AM UTC

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.


CA Carlo February 9, 2016 05:23 PM UTC

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!


RU Ragavee U S Syncfusion Team February 10, 2016 04:03 AM UTC

Hi Carlo,

Thanks for your update.

We are happy that your requirement is achieved.

Regards,
Ragavee U S.

Loader.
Up arrow icon