0

I have following static list which i am returning in my razorPage and displaying its properties on the page however escape characters "\n" are ignored in my View.

The list:

public static List<KalenderModel> GetEvents()
    {
        Events = new List<KalenderModel>()
        {
            new KalenderModel()
            {
                Id = 1,
                Date = DateTime.Now,
                Headline = "Grand Opening!",
                Message = "We are proud to announce opening of our library! " +
                "\nRegistering in our library allow you to borrow materials that are divided into 3 different categories: Books, E-books and Movies. " +
                "\nFurthermore from time to time we will announce various interesting and valuable events, so chceck this page frequently! " +
                "\nWelcome!"

            }
        };

        return Events;
    }

And the View:

@{
foreach (var evenemang in Model.Events)
{
    <div class="card text-center">
        <div class="card-header">
                   
        </div>
        <div class="card-body">
            <h5 class="card-title">@evenemang.Headline</h5>
            <p class="card-text">@evenemang.Message</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
        <div class="card-footer text-muted">
            Posted: @evenemang.Date.ToShortDateString()
        </div>
    </div>

}

}

lbs91
  • 113
  • 9
  • `\n` try replacing these with `
    `
    – UnknownRori May 28 '22 at 09:37
  • html in general ignores newlines (both `\n\r` and `\n`) unless being told to. there are alternatives that can help you in this [qa](https://stackoverflow.com/questions/4220381/replace-line-break-characters-with-br-in-asp-net-mvc-razor-view). – Bagus Tesa May 28 '22 at 09:39
  • thank you I found soultion by using @evenemang.Message – lbs91 May 28 '22 at 09:53

0 Answers0