-
-
-
Daily Quote
If you don't like what you're doing, then don't do it. Ray Bradbury -
Joke of the Day
-
Like my website? Buy me a Cigar
-
Support Stack Exchange!
-
-
-
Displaying multiline fields in MVC
Tuesday, 11 November 2025 16:15
-
So I learned a few things, wanted to document them real quick. I often have multiline text fields, such as "Notes". I want to show them in the Details page with the line returns.
If my Notes are in HTML:
Use Html.Raw on the Details page, that will display all HTML properly formatted:
<dd>
@Html.Raw(Model.Body)
</dd>If my Notes are in Text:
Use CSS with the multiline class. In sites.css, add this class. I use pre-line instead of pre-wrap to avoid a large indent on the first line.
.multiline {
white-space: pre-line;
}Refer to the class on the Details page, that will reflect the line feeds "\r\n":
<dd>
<span class="multiline">@Html.DisplayFor(model => model.Notes)</span>
</dd> - Category
- Azure
- Keywords
- Development, CSS