0

I got the following code in my asp.net mvc VIEW.

<div class="row">
  <div class="col-sm-12">
    <span id="errorId" class="glyphicon glyphicon-remove" style="color: #FF0004;"></span> @Model.ErrorMessage
   </div>
</div>

The @Model.ErrorMessage may contain contain multiple strings but when the View is rendered, I don't see the line break. I tried adding <br /> and \r\n but its all rendered on 1 line.

Here is a sample of the returning error message:

The first field is required.\r\nThe second field is required.\r\nThe third field is required.\r\n

I replaced the \r\n with <br> line tag but it still does not work.

how can I break the string up into separate lines? Thanks.

mason
  • 31,774
  • 10
  • 77
  • 121
user1250264
  • 897
  • 1
  • 21
  • 54
  • In normal situations, `\r\n` won't get you a new line in an HTML page. The equivalent would be a `
    ` tag, though that's falling out of favor.
    – mason Jan 27 '16 at 21:12

2 Answers2

2

You can wrap the @Model.ErrorMessage in <pre> </pre> tags

Gregoire
  • 24,219
  • 6
  • 46
  • 73
1

HTML Linebreak? <br /> ? But it depends on your HTML if <br /> is the best, or <p> or a list <ul>.

If u want to split on \r\n then use String.Split() Method and you'll get an string[] which you can use to iterate and build your HTML list.

But all depends more or less on your HTML code.

Benjamin Abt
  • 1,730
  • 18
  • 33