0

I have a cshtml that renders a model. One of the property has "\r\n" I want to use as a line break. so what I do is call

@Model.Message.Replace("\r\n", "<br />")

But the razor engine renders as <br /> Any solution?

Steven Zack
  • 4,984
  • 19
  • 57
  • 88
  • Possible duplicate of [Replace line break characters with
    in ASP.NET MVC Razor view](https://stackoverflow.com/questions/4220381/replace-line-break-characters-with-br-in-asp-net-mvc-razor-view)
    – Heretic Monkey Oct 11 '18 at 00:18

1 Answers1

0

Just found the following solution:

 @(new HtmlString(Model.Message.Replace("\r\n", "<br />")))

It works perfectly!

Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
Steven Zack
  • 4,984
  • 19
  • 57
  • 88