在 Razor Pages 中显示字符串数组?

Displaying a string array in Razor Pages?

我正在尝试在 Razor 页面中打印出一个字符串作为列表。我有以下内容:

Aboud.cshtml.cs:

public void OnGet()
{
    Message = "Hello";

    Message = AddToMessage(new string[] {
        "This is my first page",
        "By the end of this course",
        "I will be a Razor Pages Pro!"});


}


private string AddToMessage(string[] text)
{
    string result = "";
    foreach (string txt in text)
    {
        result += txt + "\n";
    }

    result = ReplaceToUpper(result);
    return result;
}


private string ReplaceToUpper(string text)
{
    return text.ToUpper();
}

About.cshtml:

@page
@model AboutModel
@{
}

<h1>This is the about page!</h1>
<br />
<p>@{
    string[] message = @Model.Message.Split("/n");
    foreach(string text in message)
    {
        <br /><p>@text</p>;
    }

   }
</p>

页面一直打印出一串行。我也尝试过使用 unordered/ordered 列表作为 HTML 标记,但我无法使其工作。

需要其他反斜杠,所以 \n 而不是 /n

@page
@model AboutModel
@{
}

<h1>This is the about page!</h1>
<br />
<p>@{
    string[] message = @Model.Message.Split("\n");
    foreach(string text in message)
    {
        <br /><p>@text</p>;
    }

   }
</p>