Advanced Column Rendering for MVCContrib Grid with MVC3 Razor
Asked Answered
P

2

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?

Primus answered 11/3, 2011 at 23:52 Comment(0)
H
11

The following should work:

@(Html
    .Grid<SomeViewModel>(Model)
    .Columns(column => {
        column.Custom(@<div>@item.Name</div>).Named("Data");
    })
)
Highminded answered 12/3, 2011 at 8:38 Comment(2)
+1 switching @{Html.Grid....} to @(Html.Grid....) made my grid show up. Razor enclosures are strange =/Carnauba
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.Petuu
G
3

This works for me.

@(Html.Grid(Model.PaymentFileLogs)
    .AutoGenerateColumns()
    .Columns(extraColumns => extraColumns.For(c => "<i class='icon-warning-sign'></i>").Encode(false))
Guard answered 11/7, 2012 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.