Consider the following example:
<div>@ViewBag.MyData</div>
What should I do if ViewBag.MyData contains a line with "\ n" (new lines) in it that I want to change to " <br/> "? When I include " <br/> " instead of newlines, it becomes encoded in the browser, which is bad.
<br/>
How to help me?
use @Html.Raw(ViewBag.MyData.Replace("\n", "</br>"))
@Html.Raw(ViewBag.MyData.Replace("\n", "</br>"))
the following will do what you need ...
@MvcHtmlString.Create(ViewBag.MyData.Replace("\n", "</br>"))
The Create method will accept the HTML string and display it as expected if you just typed the HTML right on the page
Create
Something that html pre tag is used for
pre> defines preformatted text. The text in <pre> is displayed in a fixed-width font (usually Courier), and it saves both spaces and line breaks ...
And in the razor pattern
< pre>@ViewBag.MyData</ pre>
Source: https://habr.com/ru/post/904313/More articles:How to create an android jar project with src, res folder - androidJQuery UI autocomplete: getting a link to ul - jqueryHow to show a dialog box with two buttons (Continue / Close) in Delphi - delphiIs it good to use VirtualProtect to change a resource in Delphi? - delphiUnknown column - multiple joins in CDbCriteria - joinJQuery click menu - jquerySQL Server auto-login maximum size - sqlAcceleration perl DBI fetchrow_hashref - performanceSQL Server - Per-User-Specific Tables - designDoes the built-in function affect its connection? - c ++All Articles