0

I have a mvcjqgrid:

@(Html.Grid("dataGrid")
          .SetJsonReader(new MvcJqGrid.DataReaders.JsonReader { Id = "Id", RepeatItems = false })
          .SetRequestType(RequestType.Post)
          .AddColumn(new Column("Name").SetLabel("Name").SetSearch(true))
          .AddColumn(new Column("Email").SetLabel("E-Mail").SetSearch(true).SetFormatter(Formatters.Email))
          .AddColumn(new Column("Phone").SetLabel("Phone").SetSearch(true))
          .SetSearchToolbar(true)
          .SetUrl(Url.Action("GetData", "Controller"))
          .SetSearchOnEnter(false)
          .SetRowNum(10)
          .SetRowList(new[] { 10, 15, 20, 50 })
          .SetViewRecords(true)
          .SetPager("pager"))

and controller:

    public ActionResult GetData()
    {
        return View(new myEntity[0]);
    }

    [HttpPost]
    public JsonResult GetData(GridSettings gridSettings)
    {
        int totalRecords = DataHelper.GetCount();
        var data = DataHelper.GetData(gridSettings);
        var jsonData = new
        {
            total = totalRecords / gridSettings.PageSize + 1,
            page = gridSettings.PageIndex,
            records = totalRecords,
            rows = data
        };
        return Json(jsonData);
    }

EDIT:
so my question is how can i store GridSettings in session in right way, i need every time user backs to this page, page should be the same as when he left?
If i do:

Session["settings"] = gridSettings;

i need some way to compare stored gridSettings with the one passed to action.

Roar
  • 2,117
  • 4
  • 24
  • 39

2 Answers2

0

Why don't you use the Http Cache for this case? We can write a caching provider, and Http Cache is one implementation for this. So in the future you can extend more providers for it.

Community
  • 1
  • 1
thangchung
  • 2,020
  • 2
  • 17
  • 28
  • not the answer at all, i meen my jqgrid call public JsonResult GetData(GridSettings gridSettings) and pass gridSettings, and another i've got in session, so how can i get to know which one is correct? – Roar May 13 '13 at 11:11
0

The answer is to recreate Grid:

@{
     var setting = Session["settings"] as GridSettings;
}
@(Html.Grid("dataGrid")
          .SetJsonReader(new MvcJqGrid.DataReaders.JsonReader { Id = "Id", RepeatItems = false })
          .SetRequestType(RequestType.Post)
          .AddColumn(new Column("Name").SetLabel("Name").SetSearch(true))
          .AddColumn(new Column("Email").SetLabel("E-Mail").SetSearch(true).SetFormatter(Formatters.Email))
          .AddColumn(new Column("Phone").SetLabel("Phone").SetSearch(true))
          .SetSearchToolbar(true)
          .SetUrl(Url.Action("GetData", "Controller"))
          .SetSearchOnEnter(false)
          .SetRowNum(setting != null?setting.PageSize : 10)
          .SetPage(setting != null?setting.PageIndex : 1);
          .SetSortName(setting != null?setting.SortColumn : "");
          .SetRowList(new[] { 10, 15, 20, 50 })
          .SetViewRecords(true)
          .SetPager("pager"))
Roar
  • 2,117
  • 4
  • 24
  • 39