访问WebGrid中的模型数据

问题描述 投票:2回答:2

如何在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) 
               )
        )
asp.net-mvc-3 entity-framework-4 webgrid
2个回答
3
投票

尝试:

personGrid.Column(format: @<text>@item.Career.Title</text>) 

0
投票

@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>

}

© www.soinside.com 2019 - 2024. All rights reserved.