Miguel Moura
Miguel Moura

Reputation: 39364

Break text in different lines with \r\n

On an ASP.NET MVC the model has the following value:

TestViewModel model = new TestViewModel {
  Description = "This is a description test\r\nlorem ipsum\r\nline2\r\n\r\n-item1\r\n-item2"
}

On the view I simply have the following:

<div>@Model.Description</div>

The entire text appears in one line ... The \r\n are not making any effect.

How can I solve this?

Upvotes: 1

Views: 80

Answers (1)

haim770
haim770

Reputation: 49095

You need to convert the newline characters to HTML's <br /> element:

<div>@Html.Raw(Model.Description.Replace(Environment.NewLine, "<br />"))</div>

Upvotes: 1

Related Questions