asp.net-mvcasp.net-mvc-4razormvccontribmvccontrib-grid

Replace string concat with Razor syntax


Here is my ASP.NET MVC 4 View (Razor) code:

@Html.Grid(Model).Columns(column =>
    {
        column.For(s => s.Description + @"<div class='results'>
            <a href='#'>Link 1</a>
            <a href='#'>Link 2</a>
        </div>").Named("Description").Encode(false);
    })

As you can see I am concatenating strings there. I would like to use Razor instead. Is there any simple way to do this?

Putting <text> instead of " doesn't work...


Solution

  • Is there any simple way to do this?

    Sure, just use column.Custom instead of column.For:

    column
        .Custom(
            @<text>
                <div class="results">
                    <a href='#'>Link 1</a>
                    <a href='#'>Link 2</a>
                </div>
            </text>
        )
        .Named("Description");