问题描述:

Is there a way to pass a string with HTML tags without changing the Razor code?

Scenario (current code):

string msg = "<a href='http://www.google.com/html/'>Google</a>";

OUTPUT:

<a href='http://www.google.com/html/'>Google</a> on the page.

GOAL result:

Link to Google without changing the code "@msg".

网友答案:

You can try with

HtmlString msg = new HtmlString("<a href='http://www.google.com/html/'>Google</a>");

instead of

string msg = "<a href='http://www.google.com/html/'>Google</a>";
网友答案:

try @Html.Raw(HttpUtility.HtmlDecode(msg));

网友答案:

Hey You can edit your razor code as:

@{

     HtmlString msg = new HtmlString("Hello <br> Hello Again");
     <p style="text-align:justify;"> @msg  </p>
 } 

It's simple

相关阅读:
Top