访问WebGrid中的模型数据

时间:2011-03-29 17:09:39

标签: asp.net-mvc-3 entity-framework-4 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) 
               )
        )

2 个答案:

答案 0 :(得分:3)

尝试:

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

答案 1 :(得分:0)

@型号列表

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(列名称:“ registrationNo”,标题:“应用程序编号”,格式:@@ item.registrationNo),             grid.Column(“ progressReportSubject”,标头:“ Progress Report Subject”),             grid.Column(“ uploadDate”,标头:“ Upload Date”),             grid.Column(columnName:“ progressReportPath”,标题:“ Progress Report”,格式:@         @if(!string.IsNullOrEmpty(@ item.progressReportPath))         {                      }         其他         {

    }
    </text>)

        ))
</div>

}

相关问题