How to call another class column name in Webgrid MVC

Asked

Viewed 196 times

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)

So much Iniciativa.Codigo how much Modelo.Codigo do not work. Error appears:

Column "Initiative.Code" does not exist.

How best to call the description of a column of another class in Webgrid?

Note: Initiative and Model has relationship with MDG.

1 answer

1

I can access methods of another class similar to the one you use, but with some modifications in the code, follow 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
        )
    )
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.