Restoring Grid State

Jun 14, 2013 at 7:50 AM

First of all I would like to say what a great grid you have put together. It is very impressive, thank you.

Please can you help me with an issue I have with it. I am using the grid to display a list of venues. If the user applies a sort, and a filter then goes to page 3 and then chooses to edit a venue then they are taking to another page. They edit the venue and I return them to the list.

How can I restore the state of the grid with the same sort, filter and page ?
Jun 14, 2013 at 10:49 AM
Hi thanks,

By default grid take settings from the query string parameters and if you want to solve this problem you need to redirect user to specified url after he finished edit the venue. For example you can pass return url to edit form and after post back redirect to passed url:

Build edit url in the view:
@Html.Action("Edit", new {returnUrl = Request.Path, id= item.Id})
it produce url line like:


then in edit action redirect user to passed url:
public ActionResult Edit(VenueModel model, string returnUrl )
      ....//do something

      if (string.IsNullOrWhiteSpace(returnUrl) || !model.ReturlUrl.StartsWith("/"))
                return RedirectToAction("List");
            return Redirect(model.ReturlUrl);
Jun 14, 2013 at 12:16 PM
Thanks for this advice. This solved the situation for me in the edit scenario but I found I could use it even more effectively in that any time the user returned to the venue list it would restore their settings. This was done by having the link to the list being for the action VenueListRestore. The way this is coded means that the user can clear a filter on the grid successfully as it gets redirected to the VenueList action rather than the VenueListRestore action.
public ActionResult VenueListRestore()
            return this.RedirectToAction("VenueList");

        // GET: /Admin/Admin/VenueList
        public ActionResult VenueList()
            if (null != Session["VenueListRestore"] && null != Session["VenueListURL"])
                string strURL = Session["VenueListURL"] as string;
                Session["VenueListURL"] = null;
                return Redirect(strURL);

            Session["VenueListRestore"] = null;
            Session["VenueListURL"] = Request.RawUrl;

            VenueListModel model = new VenueListModel(Url);

            db.Configuration.LazyLoadingEnabled = true;
            db.Configuration.ProxyCreationEnabled = false;
            var query = from v in db.Venues
                        orderby v.Id
                        select v;
            model.GridData = query;

            return View(model);