Доступ к данным модели в WebGrid - PullRequest
2 голосов
/ 29 марта 2011

Как получить доступ к дополнительной информации о подмоделях в 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 ]

3 голосов
/ 30 марта 2011

Попробуйте:

personGrid.Column(format: @<text>@item.Career.Title</text>) 
0 голосов
/ 12 февраля 2019

@ Список моделей

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", заголовок: "№ приложения", формат: @@ item.registrationNo), grid.Column ("progressReportSubject",заголовок: «Тема отчета о прогрессе»), grid.Column («uploadDate», заголовок: «Дата загрузки»), grid.Column (columnName: «progressReportPath», заголовок: «Отчет о прогрессе», формат: @ @if (! string).IsNullOrEmpty (@ item.progressReportPath)) {} else {

    }
    </text>)

        ))
</div>

}

...