Search code examples
c#asp.net-corerazorline-breaksrazor-pages

Line Break in cshtml.cs


I'm trying to have a line break in cshtml.cs

This is the code:

string error ="";
foreach (ValidationFailure fail in check.Errors)
{
     error += (fail.ErrorMessage + "<br>");
}
ViewData["Message"] = error;

I have tried <br>, <br/>, \n, \r but 'error' still prints out.

Any idea how to solve this?


Solution

  • I have solved it. I should put a double slash instead of just 1.

    string error ="";
    foreach (ValidationFailure fail in check.Errors)
    {
         error += (fail.ErrorMessage + "\\n");
    }
    ViewData["Message"] = error;