Reputation: 9289
I'm using MVC3 webgrid to display, sort and paginate data. The display is fine, but when I click on a new page or request a sort, nothing is happening.
This is the code that I'm using:
@if (Model.AdsList != null)
{
WebGrid adGrid = new WebGrid(Model.AdsList, rowsPerPage: 10, canSort: true, ajaxUpdateContainerId: "adsGrid");
<div>
@adGrid.Pager(WebGridPagerModes.NextPrevious);
@adGrid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
htmlAttributes: new { id = "adsGrid", width = "100%" },
columns: adGrid.Columns(
//columns
));
</div>
}
The data is loading correctly, but none of the links generated are working. Is there anything I need to do in controller
for paging and sorting?
EDIT : I am getting this page as a result of post operation from another page .There is not GET action with same name in the controller.
code is shown below in controller
[HttpPost]
public ActionResult Search(SearchModel model)
{
//some operation
return view(model);
}
I also like to know how paging is working . Is the webgrid query against data base every time when i click next page or sort links?
Upvotes: 0
Views: 3749
Reputation: 1079
var grid = new WebGrid(source: Model, rowsPerPage: 6,canPage: true, canSort: true, );
@grid.GetHtml(headerStyle: "gridtableheader", footerStyle: "paging",
columns:
grid.Columns(
//Columns
),
mode: WebGridPagerModes.All)
// different modes of paging
mode: WebGridPagerModes.FirstLast
mode: WebGridPagerModes.NextPrevious
mode: WebGridPagerModes.Numeric
Hope This will solve your problem
Upvotes: 4