How to render HTML string in ASP.NET MVC?

2019-01-22 05:20发布

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

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?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-22 06:19

You can use the Html.Raw() method for that.

查看更多
登录 后发表回答