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

怎甘沉沦 提交于 2019-12-07 15:32:56

问题


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?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/7683559/how-to-add-html-inside-asp-net-mvc-3-webgrid-column-name-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!