Html.Raw 在控制器中
Html.Raw in controller
我从编辑那里获取内容,因此内容包括 html 标签,例如“dddd”
我必须从内容中删除 html 标签,因为我使用 itextsharp.DLL 将此内容写入 PDF(在 c#-controller 操作中生成 pdf),但 itextsharp 内容带有 [=27=] 标签,它不呈现 html 标签,如您在屏幕下方所见
c#(action -controller)中没有Html.Raw函数或HtmlHelper.Raw函数
我该怎么办?我尝试使用正则表达式删除 html 标签,但内容非常复杂且是动态的,因此有很多 html 标签
一种方法是使用像 HTML Agility Toolpack 这样的 HTML 解析器。正如您所描述的,我已经成功地使用它来解决问题(但在其他方面与它的开发无关)。来自网站:
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
您会在网上找到大量示例来满足您的需求。
您可以像这样在控制器中使用 Html.Raw 和 Html.Json
例子
如果我在视图中使用它
var attrilist = @Html.Raw(Json.Encode(attriFeildlist));
然后我可以在 Controller 中使用它作为此代码的替代
var jsonencode = System.Web.Helpers.Json.Encode(attriFeildlist);
var htmlencode= WebUtility.HtmlEncode(jsonencode);
我从编辑那里获取内容,因此内容包括 html 标签,例如“dddd”
我必须从内容中删除 html 标签,因为我使用 itextsharp.DLL 将此内容写入 PDF(在 c#-controller 操作中生成 pdf),但 itextsharp 内容带有 [=27=] 标签,它不呈现 html 标签,如您在屏幕下方所见
c#(action -controller)中没有Html.Raw函数或HtmlHelper.Raw函数
我该怎么办?我尝试使用正则表达式删除 html 标签,但内容非常复杂且是动态的,因此有很多 html 标签
一种方法是使用像 HTML Agility Toolpack 这样的 HTML 解析器。正如您所描述的,我已经成功地使用它来解决问题(但在其他方面与它的开发无关)。来自网站:
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
您会在网上找到大量示例来满足您的需求。
您可以像这样在控制器中使用 Html.Raw 和 Html.Json
例子
如果我在视图中使用它
var attrilist = @Html.Raw(Json.Encode(attriFeildlist));
然后我可以在 Controller 中使用它作为此代码的替代
var jsonencode = System.Web.Helpers.Json.Encode(attriFeildlist);
var htmlencode= WebUtility.HtmlEncode(jsonencode);