Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display raw HTML using WebGrid in ASP.NET MVC 3

I have a grid like this:

WebGrid grid = new WebGrid(source: Model, rowsPerPage: 5, ajaxUpdateContainerId: "GridContainer");

Now, I want to display "MyContent" column as raw HTML. What should I do?

<div id="GridContainer">
    @grid.GetHtml(columns:
        grid.Columns(
            grid.Column(
                columnName: "MyContent",
                //Format: What should I put here?
            )
        )
    )
</div>
like image 268
Triet Doan Avatar asked Jan 15 '13 02:01

Triet Doan


1 Answers

Use

<div id="GridContainer">
    @grid.GetHtml(columns:
        grid.Columns(
            grid.Column(
                columnName: "MyContent",
                format: (item) =>
                    {
                       var links = Html.ActionLink("Edit",   "Edit",    new {id = item.PrimaryKey})  + " | " +
                                   Html.ActionLink("Details","Details", new { id = item.PrimaryKey}) + " | "+
                                   Html.ActionLink("Delete", "Delete",  new { id = item.PrimaryKey});

                       return Html.Raw(links);
                    }
                )
            )
        )

which renders as

<td>
    <a href="/Home/Edit/5">Edit</a> |
    <a href="/Home/Details/5">Details</a> |
    <a href="/Home/Delete/5">Delete</a>
</td>
like image 181
heads5150 Avatar answered Sep 24 '22 15:09

heads5150