Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced Column Rendering for MVCContrib Grid with MVC3 Razor

I'm trying to build a custom column for an MVCContrib grid, but an getting tripped up by the Razor syntax. Here is my code for building a custom column:

@{Html.Grid(Model).Columns(column =>
    {
        column.For("Data").Do(p => {
        <div>@p.Name</div>
        });
    }).Render();
}

How do you mark the line containing the div so that Razor will treat the line as HTML?

like image 215
user330468 Avatar asked Mar 11 '11 23:03

user330468


2 Answers

The following should work:

@(Html
    .Grid<SomeViewModel>(Model)
    .Columns(column => {
        column.Custom(@<div>@item.Name</div>).Named("Data");
    })
)
like image 132
Darin Dimitrov Avatar answered Nov 11 '22 12:11

Darin Dimitrov


This works for me.

@(Html.Grid(Model.PaymentFileLogs)
    .AutoGenerateColumns()
    .Columns(extraColumns => extraColumns.For(c => "<i class='icon-warning-sign'></i>").Encode(false))
like image 43
JefClaes Avatar answered Nov 11 '22 12:11

JefClaes