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

Dec 24, 2013 at 7: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
Dec 27, 2013 at 1: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:
Dec 30, 2013 at 10: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;
Jan 9, 2014 at 2: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
Also if you create own grid class
var grid = new OrdersGrid(repository.GetAll());