c# – How to call column name from another class in WebGrid MVC


I have this Listar.cshtml view

@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),
            canSort: false,
            header: IniciativaResources.Titulo),
        grid.Column("DescricaoChefes", ODMResources.ProjectChief),
            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 a column description from another class in WebGrid?

Note: Initiative and Model is related to the MDG.


I can access methods from another class in a similar way to the one you use, but with some modifications in the code, the example follows:

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),
            format: (item) =>
                "<button type='button' class='btn btn-default' id='btnDetalhes'" +
                    + @item.Id +
                + "<span class='glyphicon glyphicon-edit'> </span> Editar </button>",
            canSort: false
Scroll to Top