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, it opens the table in a brand new window on it’s own? Anybody know why this happens? It is contained within a partial view.
The code for the grid is as follows:
@{
var grid = new WebGrid(
source: Model,
defaultSort: "StudyName",
rowsPerPage: 10,
canPage: true,
canSort: true);
}
<div>
@if (Model.Any())
{
@grid.GetHtml(
tableStyle: "resultTable",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
//List of columns
)
)
}
I’ve answered my own question as I have found the solution, and by sharing it may help somebody else.
Effectively, I simply had to include the following line in the webgrid declaration:
Where “tableDiv” is the containing element.