如何呈现ASP.NET MVC HTML字符串? [英] How to render HTML string in ASP.NET MVC?

查看:118
本文介绍了如何呈现ASP.NET MVC HTML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主页,我有code @ {Html.RenderPartial(_ Partial1.cshtml);} ,并在我的部分,我有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

我要输出 ABC 有一些CSS错误的款式,但事实上,我&LT; D​​IV CLASS =错误&GT; ABC&LT; / DIV&GT; - 当然,没有风格在那里。我如何让它间preTED为HTML源代码code和不是字符串?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆