如何在 ASP.NET MVC 中呈现 HTML 字符串? [英] How to render HTML string in ASP.NET MVC?
本文介绍了如何在 ASP.NET MVC 中呈现 HTML 字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的主页上,我有代码 @{Html.RenderPartial("_Partial1.cshtml");}
,在我的 Partial 上,我有一个 HTML 字符串:
On my main page, I have the code @{Html.RenderPartial("_Partial1.cshtml");}
, and on my Partial, I have an HTML string:
@{
// The string is actually dynamic, not static. This is here for simplicity
string abc="<div class="error">abc</div>";
}
@abc
我想输出带有一些 CSS 错误样式的 abc
,但我实际上得到了 <div class="error">abc</div>
- 当然,没有样式.如何将其解释为 HTML 源代码而不是字符串?
I want to output abc
with some CSS error styles, but I actually got <div class="error">abc</div>
- of course, no styles there. How do I make it interpreted as HTML source code and not a string?
推荐答案
您可以使用 Html.Raw()
方法.
这篇关于如何在 ASP.NET MVC 中呈现 HTML 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文