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".
Creates an HTML-encoded string using the specified text value. Determines whether the specified string contains content or is either null or empty.
If you want to append some HTML text to the document. body then you should use document. body. insertAdjacentHTML('beforeend', str); .
DisplayFor() The DisplayFor() helper method is a strongly typed extension method. It generates a html string for the model object property specified using a lambda expression.
try @Html.Raw(HttpUtility.HtmlDecode(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>";
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With