I create an application using asp mvc razor + mvc grid.
My problem is : i have one view that contain multiple action that return partial view, in each partial view there is a grid that display the data. I am using mvc contrib grid which support paging and sorting.
My view (index.cshtml) :
<div class="row-fluid">
<div id="formations" class="control-group">
@Html.Action("Formations")
</div>
<div id="pools" class="control-group">
@Html.Action("Pools")
</div>
<div id="zones" class="control-group">
@Html.Action("Zones")
</div>
Formations action :
public ActionResult Formations(GridSortOptions sort, int? page, string filter = "all")
{
IPagination<StratUnitVo> pagination = ....
return PartialView("_Formations", pagination);
}
Partial View _Formations :
@Html.Grid(Model).Sort(ViewData["sort"] as GridSortOptions).Columns(col =>
{
col.For(p => Html.ActionLink(p.LongName, "EditFormation", "Stratigraphy", new { id = p.Id }, null).ToHtmlString()).Encode(false).Named(Locale.Name).SortColumnName("LongName");
col.For(p => p.FormCode).Named(Locale.Code);
col.For(p => p.ReferenceStratUnit.LongName).Named(Locale.ReferenceFormation);
}).Attributes(@class => "table table-condensed table-striped table-hover")
@if (Model.Count() > 0)
{
@Html.Raw(@Html.Pager(Model)));
}
Other action and view is most like sample above (just difference in the model data).
My problem is :
- When i click the navigation paging in one grid (example : Formations), the other grid (Pools and Zones) will be navigate to. For example : click page 2 in formations grid will move another grid to page 2 too.
- When i click the column header in one grid (which mean i want to sort the data), the whole page is replaced by partial view. What i want is only the grid that i have clicked is sorted.
How can i fix that ?
Thanks!
Well, I just solved my problem like this :
For paging : add new parameter for each action called ‘type’ and validate based on the parameter.
For sorting : use ajax sort for mvc grid :