Home
Search

Start | Blogs | Umbraco | Line breaks text area

2019-10-17

Umbraco

Umbraco line breaks are not displayed from Text Area solution

You have printed out the text of a TextArea property type in Umbraco, but the line breaks are ignored?

Solution:
Wrap the text in Html.Raw() and use the string extension method Replace() for \n with <br>.

 

Like so:


 @Html.Raw(Model.Preamble.Replace("\n", "<br />"))

Where Preamble is the mapped Text Area string property.

\n stands for line break but it does not automatically get used when displayed in the web browser so it needs to be replaced with <br> tags.

 

Don't forget to null check Preamble in this case before doing replace