6

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?

user330468
  • 381
  • 2
  • 4
  • 6

2 Answers2

11

The following should work:

@(Html
    .Grid<SomeViewModel>(Model)
    .Columns(column => {
        column.Custom(@<div>@item.Name</div>).Named("Data");
    })
)
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • +1 switching `@{Html.Grid....}` to `@(Html.Grid....)` made my grid show up. Razor enclosures are strange =/ – Chris Marisic Mar 21 '11 at 18:13
  • Thanks for this post; I was originally trying to create my own renderer, but to no avail. I ended up just using a custom column to display the data how I wanted and it worked perfectly. – Justin Helgerson Jan 11 '12 at 15:17
3

This works for me.

@(Html.Grid(Model.PaymentFileLogs)
    .AutoGenerateColumns()
    .Columns(extraColumns => extraColumns.For(c => "<i class='icon-warning-sign'></i>").Encode(false))
JefClaes
  • 3,275
  • 21
  • 23