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?
Asked
Active
Viewed 1.2k times
2 Answers
12
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>

Massimo Zerbini
- 3,125
- 22
- 22
-
@Max YES!! I have been trying to do this for days (ahem.. weeks). Thanks :-) – Peter Feb 01 '13 at 08:38
-
Very nice solution thank you. I almost trying to find the solution for an hour. – mostafakvd Aug 14 '17 at 12:25
0
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.

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928