View Model:
public class Note
{
[DataType(DataType.MultilineText)]
public string Text { get; set; }
}
Default editor template renders a <textarea>
element with the newlines preserved.
The default display template renders the text as a single string with the newlines removed.
I tried this, but it doesn't work:
~/Views/Shared/EditorTemplates/MultilineText.cshtml
@model string
@Html.Raw(Model.Replace(System.Environment.NewLine, "<br />"))
I can do something silly like @Html.Raw(Model.Replace("e", "<br />"))
and it will work but of course I only want to replace the newline characters the <br />
element! I also tried using @"\n"
and that didn't work either.
Any ideas?
Thanks!
You could try this:
@Html.Raw("<pre>"+ Html.Encode(Model) + "</pre>");
This will preserve your content and show it as-is.
Try @Html.Raw(Model.Replace("\r\n", "<br />"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With