i 我在部分视图上运行了这个网格视图,但我想在每次更新数据库或每 3 秒更新一次数据?
分部视图从 index.cshtml 调用,只将调用的 and 模型传递给它。@Html.部分("_CommissionDeskReport",模型)
我尝试使用 javascript,但它一直在刷新整个页面而不是部分视图。
这是部分视图代码,请做建议?
_CommissionDeskReport.cshtml
@model IEnumerable<Socks.Domain.Models.CommissionDeskReport>
@{
Layout = null;
//WebGrid grid = new WebGrid(Model, rowsPerPage: 3);
}
<h2>Commission Desk Report</h2>
<div id="EmployeeViewGrid">
@{
var grid1 = new WebGrid(source: Model, canPage: true, ajaxUpdateContainerId: "gridContent");
@grid1.GetHtml(mode: WebGridPagerModes.All, tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
rowStyle: "row",
htmlAttributes: new { id = "employeeGrid" },
fillEmptyRows: false,
columns: grid1.Columns(
grid1.Column("Period", header: "Period"),
grid1.Column("Value", format: (item) => new HtmlString("£ " + Convert.ToString(item.value)), header: "Value"),
grid1.Column("Average", format: (item) => new HtmlString("£ " + Convert.ToString(item.average)), header: "Average"),
grid1.Column("Percent", format: (item) => new HtmlString(Convert.ToString(item.Percent) + " %"), header: "Percent"))
)
}
</div>
<style type="text/css">
.row {
background: #fff;
}
.header {
background: #bbb;
}
.alt {
background: #d6e3f2;
}
.webGrid {
border: 1px solid #bbb;
}
.webGrid th, .webGrid td {
padding-left: 10px;
}
</style>
@{
Layout = null;
}
<script src="~/Scripts/lib/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(function () {
setInterval(function () {
$('#gridView').load('CommissionDeskReportPartial');
},
3000);
});
</script>
<div id="gridView">
</div>
@*This code will go on your main view e.g Index.cshtml to call you partial method*@
// this will be you partial method on the controller
public PartialViewResult CommissionDeskReportPartial()
{
List<Report> report = report.List(UserId).ToList();
return PartialView("_CommissionDeskReport", report);
}