c# - GridMvc 错误地在列中显示文本

标签 c# html asp.net-mvc html-encode grid.mvc

我对 GridMvc 库有疑问。我想添加包含带
分隔符的字符串连接表的列,这是我的代码:

columns.Add()
       .RenderValueAs(
           row => string.Join(
               HttpContext.Current.Server.HtmlEncode("<br/>"),
               row.QuestionDifficultyToPosition.Select(
                   r => r.Difficulty.DifficultyName).ToArray()))
       .Titled("Difficulties")
       .Filterable(true)
       .Sortable(true);

但结果我得到:

Easy&lt;br/&gt;Hard

您知道为什么它不起作用吗?

最佳答案

您看到的是编码的 <br/> , 因此您需要删除对 HtmlEncode() 的调用方法。此外,来自 docs ...

you need to disable default encoding and satinizing cell values, using Encoded and Sanitized method.

columns.Add()
       .Encoded(false)
       .Sanitized(false)
       .RenderValueAs(
           row => string.Join(
               "<br/>",
               row.QuestionDifficultyToPosition.Select(
                   r => r.Difficulty.DifficultyName).ToArray()))
       .Titled("Difficulties")
       .Filterable(true)
       .Sortable(true);

关于c# - GridMvc 错误地在列中显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18773727/

相关文章:

c# - 如何从变量模板字符串中提取动态对象并再次将其合并?

c# - 如果值已更改 C#,则将参数从文本框发送到存储过程

html - 星级在白色背景下不可见

javascript - Codeigniter - 打印网页时遇到问题

javascript - 如何在单页应用程序中处理敏感数据

c# - 多线程问题

c# - JSONDeserializer 从 Json 字符串到对象列表

javascript - jQuery 菜单 - 如何在菜单上放置箭头来表示子菜单?

asp.net-mvc - JSP 相当于 ASP.NET MVC 部分 View ?

jquery - MVC 将数据传入和传出 Bootstrap Modal