我开始使用 MVC 4 在 WebGrid 上工作,并且能够按预期显示分页/排序及其工作......如果我尝试使用 ajax 来制作它,那么它会完成完整的帖子。
视图:- 部分视图:(_hostajax.cshtml)
@model IEnumerable<issoa_ef.host>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@{
var grid = new WebGrid(
Model, rowsPerPage: 2,
defaultSort: "HostFirstName", ajaxUpdateContainerId: "ajaxgrid");
}
<div id="ajaxgrid">
@grid.GetHtml(
tableStyle: "gridTable",
headerStyle: "gridHead",
footerStyle: "gridFooter",
rowStyle: "gridRow",
alternatingRowStyle: "gridAltRow",
columns: grid.Columns
(
grid.Column("HostFirstName", header: "First Name", format: @<text>@Html.ActionLink((string)item.HostFirstName, "Details", "Host", new { id = item.HostId }, null)</text>),
grid.Column("HostMiddleName", header: "Middle Name"),
grid.Column("HostLastName", header: "Last Name"),
grid.Column("HostEmailAddress", header: "eMail Address")
)
)
</div>
控制器:
public ActionResult Index()
{
var model = db.host.ToList();
if (Request.IsAjaxRequest())
return PartialView("_hostajax", model);
else
return View(model);
}
索引页面:
<h2>@ViewBag.Message</h2>
<p>
@Html.ActionLink("Request Deployment", "CreateDeployment")
</p>
@Html.Partial("_hostajax", Model)