Search code examples
asp.net-mvc-3entity-framework-4webgrid

Access Model Data in WebGrid


How do I access additional sub-model information within a 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) 
               )
        )

Solution

  • Try:

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