Embarrassingly newbie question:
I have a string
field in my model that contains line breaks.
@Html.DisplayFor(x => x.MultiLineText)
Inspired by DisplayTemplates for common DataTypes,
I override (introduce?) a default DisplayTemplate for DataType.MultilineText
, /Views/Shared/DisplayTemplates/Multiline.cshtml
containing just this line:
@this.Model
Of course you could also introduce a css-class, or replace newlines inside the view, if you prefer that.
(I guess this template is automatically resolved, because I had no need for UIHint
or any other reference or registration.)
Using the DisplayTemplate instead of introducing a HtmlHelper
-method has the advantage, that it trickles down to properties and views that are not explicitly defined (e.g. DisplayFor(MyClassWithMultilineProperties)
will now also correctly display MyClassWithMultilineProperties.MultilineText
, if only the property was annotated with [DataType(DataType.MultilineText)]
.