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!
@"\n"didn't work you need to use"\n"the @ forces the string to be parsed as a literal.