Returning original page of the grid after going to a different view.

Dec 24, 2013 at 8:34 PM
I have a GridMvc grid in my project. The grid lists a series of phone numbers and contains several pages. When I click an edit link on one of the rows of the grid, I am taken to the edit page where I can edit the particular phone number. My problem is when I save the edit and return to the grid view, I can't figure out how to land on the same page I left; I always land on the first page.

Some detailed help would be appreciated
Coordinator
Dec 27, 2013 at 2:39 AM
Hi you need to store grid settings to the session and refirect user to specific URL, when he submit your edit form.

Please see how to do this: https://gridmvc.codeplex.com/discussions/465397
Dec 30, 2013 at 11:36 PM
I am saving the settings in session, and when returning to the page, the filters are all in the querystring and this works great. However, I have not been able to figure out how to get the page number back.

This is where I save the settings to session:
private INumberRepository repository;
    public NumberController(INumberRepository numberRepository)
    {
        repository = numberRepository;
        var settings = new QueryStringFilterSettings();
        if (settings.FilteredColumns.Count() > 0) System.Web.HttpContext.Current.Session["filters"] = settings;

    }
This is where I get the settings out of session:
private string BuildReturnUrl()
   {
       var filterSettings = System.Web.HttpContext.Current.Session["filters"];
        var url = new UriBuilder(Url.Action("ListGrid", "Number", "", Request.Url.Scheme));
        if (filterSettings != null)
            url.Query = GetGridFilterQueryString(filterSettings as IGridFilterSettings); //restore grid filter settings
        return url.ToString();
   }

   private string GetGridFilterQueryString(IGridFilterSettings settings)
    {
        var filteredColumns = settings.FilteredColumns.ToList();
        var returnString = string.Join("&", filteredColumns.Select(f => "grid-filter=" + HttpUtility.UrlEncode(f.ColumnName + "__" + (int)f.FilterType + "__" + f.FilterValue)));
        return returnString;
   }
Coordinator
Jan 9, 2014 at 3:14 AM
Grid.mvc retrive current page from IGridPager interface with can be overriden, if you use default implementation from query string you can read current page like
Request.QueryString["grid-page"]
Also if you create own grid class
var grid = new OrdersGrid(repository.GetAll());
Debug.Write(grid.Pager.CurrentPage);