user983443
user983443

Reputation: 33

How to add Html inside ASP.NET MVC 3 WebGrid Column Name (Header)

I am unable to add html inside WebGrid column name(at header)? When I add html inside column name then webgrid encodes that. Is this is not possible to add html inside WebGrid column name?

Upvotes: 3

Views: 12083

Answers (2)

Massimo Zerbini
Massimo Zerbini

Reputation: 3191

There is a method to change html generated by an MVC Helper, but it's not very comfortable. In general you can write this command:

@( new HtmlString( Component.HelperMethod().ToHtmlString().Replace("[replacetag]", "My Content")) )

Here is an example using a grid component:

<div id="grid">
    @(new HtmlString(
        grid.GetHtml(
        tableStyle: "grid",
        headerStyle: "header",
        rowStyle: "row",
        footerStyle: "footer",
        alternatingRowStyle: "altRow",
        columns: grid.Columns(
                     grid.Column("Name", "[replacethis]"),
                     grid.Column("Surname", "Surname"),
                     grid.Column("Email", "Sender Email"),
                     grid.Column("Id", "", format: (item) => item.GetSelectLink("Select"), canSort: false))
).ToHtmlString().Replace("[replacethis]", "<b>Name</b>")
)
)    
</div>

Upvotes: 12

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

I don't think that there is a way to directly write HTML in the header of a WebGrid. One possible workaround is to append the desired with client side javascript.

Upvotes: 0

Related Questions