Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 663
user983443 Avatar asked Feb 03 '26 03:02

user983443


1 Answers

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>
like image 51
Massimo Zerbini Avatar answered Feb 04 '26 20:02

Massimo Zerbini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!