How to call column name from another class in the MVC WebGrid

3

I have this view Listar.cshtml

@model IEnumerable<ODM>
@{
    var idGrid = "grid" + this.ViewBag.IdParameters ?? string.Empty;
    var grid = new IBM.Web.Helpers.WebGrid(id: idGrid, rowsPerPage: this.RowsPerPage, ajaxUpdateContainerId: idGrid);
    var columns = new WebGridColumn[] {
        grid.Column("Codigo", ODMResources.Codigo),
        grid.Column("DataEmissao", ODMResources.DataEmissao),
        **grid.Column("Iniciativa.Codigo"**,
            canSort: false,
            header: IniciativaResources.Titulo),
        grid.Column("DescricaoChefes", ODMResources.ProjectChief),
        grid.Column("Modelo.Codigo",
            canSort: false,
            header: ModeloResources.ModeloReferencia),
        //grid.Column("DescricaoResponsaveis", ODMResources.ProjectResponsible),
        grid.Column("Causal", ODMResources.Causal),
        grid.Column("Estado", ODMResources.Estado),

}
@grid.GetHtmlExtended(this.Model, this.RowsCount, page: this, columns: columns)

Both Iniciativa.Codigo and Modelo.Codigo do not work. The error appears:

  

Column "Initiative.Code" does not exist.

What is the best way to call the description of a column of another class in the WebGrid?

Note: Initiative and Model has an MDG relationship.

    
asked by anonymous 17.08.2015 / 21:55

1 answer

1

I can access methods of another class similarly to what you use, but with some modifications to the code, follow the example:

var grid = new WebGrid(Model.List, canSort: false, canPage: false);

var htmlString = grid.GetHtml
(
    tableStyle: "webGrid table table-striped table-hover",
    htmlAttributes: new { id = "DataTable" },
    headerStyle: "header",
    alternatingRowStyle: "alt",

    columns: grid.Columns
    (
        grid.Column("Id", "Código", canSort: false),
        grid.Column("Modelo.Nome", "Nome", canSort: false),
        grid.Column
        (
            "Editar",
            format: (item) =>
                "<button type='button' class='btn btn-default' id='btnDetalhes'" +
                "onclick='editar("
                    + @item.Id +
                ")'>"
                + "<span class='glyphicon glyphicon-edit'> </span> Editar </button>",
            canSort: false
        )
    )
);
    
09.01.2016 / 00:36