【发布时间】:2020-07-27 17:44:53
【问题描述】:
我正在尝试将字符串打印为 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>
页面一直在一个字符串中打印出该行。我也尝试使用无序列/有序列表作为 HTML 标记,但我无法使其工作。
【问题讨论】:
标签: visual-studio razor razor-pages