Consider the following example:
<div>@ViewBag.MyData</div>
What to do if ViewBag.MyData contains a string with “\n” (newlines) in it, that I want to change into “<br/>“? When I include “<br/>” instead of the newlines, it gets encoded in the browser, which is bad.
How can I help this?
use
@Html.Raw(ViewBag.MyData.Replace("\n", "</br>"))