我正在使用MVC3中的WebGrid进行部分页面更新,但是当我使用$('#grid')。html(数据)更新我的网格,然后单击网格中的col / link以按该列排序页面get只用非css格式的网格重新加载。我该如何解决这个问题?
Index.cshtml
// ...
// grid partial view
<div id="gridview" class="gen">@Html.Partial("_gridPartialView", Model.Data)</div>
// On button click on main page to get filtered data to new grid
$.get('@Url.Action("GetFilteredData")', { 'statusFilter': filterstuff }, function (data) {
$('#gridview').html(data);
});
_gridPartialView.cshtml
@model IEnumerable<.Models.Data>
@{
var grid = new WebGrid(source: Model,
//defaultSort: "DataId",
rowsPerPage: 50);
}
@grid.GetHtml(
tableStyle: "webgrid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("DataId", "Id"),
grid.Column("DataName", "Name"),
//...
控制器ActionResult:
public ActionResult GetFilteredData(int[] statusFilter)
{
// Do filtered query on data model
return PartialView("_gridPartialView", cvm.Campaigns);
}
答案 0 :(得分:3)
将网格声明更改为:
var grid = new WebGrid(source: Model,
//defaultSort: "DataId",
ajaxUpdateCallback: "GridUpdate",
ajaxUpdateContainerId: "grid"
rowsPerPage: 50);
确保您的.GetHtml方法具有:
@grid.GetHtml(
htmlAttributes: new { id = "grid" },
//.. rest of the options here
)
并将以下内容添加到 Index.cshtml
<script type="text/javascript">
function GridUpdate(data) {
$('#gridview').html(data);
}
</script>