访问WebGrid中的模型数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了访问WebGrid中的模型数据相关的知识,希望对你有一定的参考价值。
如何在WebGrid中访问其他子模型信息?
var personGrid = new WebGrid(source: Model.People,
ajaxUpdateContainerId: "personGrid",
ajaxUpdateCallback: "jQueryTableStyling",
defaultSort: "PersonID");
@personGrid.Gethtml(
tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "zebra",
columns: personGrid.Columns(
personGrid.Column("PersonID", "Person ID"),
personGrid.Column("Name", "Name"),
// This line isn't working and I'm not sure how to get it to work.
personGrid.Column(model => model.Career.Title)
)
)
答案
尝试:
personGrid.Column(format: @<text>@item.Career.Title</text>)
另一答案
@model列表
WebGrid grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 10, ajaxUpdateContainerId: "divDataList");
<div id="divDataList">
@grid.GetHtml(tableStyle: "table-user-information table table-bordered table-striped",
headerStyle: "webgrid-header",
fillEmptyRows: false,
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: grid.Columns(
grid.Column(header: "S No.", style: "white", format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex),
grid.Column(columnName:“registrationNo”,header:“Application No.”,格式:@@ item.registrationNo),grid.Column(“progressReportSubject”,header:“Progress Report Subject”),grid.Column(“uploadDate” “,header:”Upload Date“),grid.Column(columnName:”progressReportPath“,header:”Progress Report“,格式:@@if(!string.IsNullOrEmpty(@ item.progressReportPath)){} else {
}
</text>)
))
</div>
}
以上是关于访问WebGrid中的模型数据的主要内容,如果未能解决你的问题,请参考以下文章