CS1002 ; が必要です
<text>
タグを利用する必要があります。using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorPageTextTag.Pages
{
public class page1Model : PageModel
{
public class Item
{
public string Name;
public int price;
}
public Item[] Items { get; set;}
public void OnGet()
{
Items = new Item[3];
Items[0] = new Item { Name = "ぺんぎんクッキー", price = 110 };
Items[1] = new Item { Name = "らくだキャラメル", price = 85 };
Items[2] = new Item { Name = "しろくまアイス", price = 230 };
}
}
}
@page
@model RazorPageTextTag.Pages.page1Model
@{
}
<html>
<head>
</head>
<body>
<h2>RazorPage のテスト</h2>
<p>
@for (int i = 0; i < 2; i++) {
Name: @Model.Items[i].name<br />
Price: @Model.Items[i].price<br />
}
</p>
</body>
</html>
@page
@model RazorPageTextTag.Pages.page1Model
@{
}
<html>
<head>
</head>
<body>
<h2>RazorPage のテスト</h2>
<p>
@for (int i = 0; i < 2; i++) {
@Model.Items[i].name<br />
@Model.Items[i].price <br />
}
</p>
</body>
</html>
<text>
タグを利用します。@page
@model RazorPageTextTag.Pages.page1Model
@{
}
<html>
<head>
</head>
<body>
<h2>RazorPage のテスト</h2>
<p>
@for (int i = 0; i < 2; i++) {
<text>Name:</text> @Model.Items[i].name<br />
<text>Price:</text> @Model.Items[i].price <br />
}
</p>
</body>
</html>
text
タグで囲んだ部分がページの文字列として出力されています。text
タグはページの出力には含まれていないことがわかります。<html>
<head>
</head>
<body>
<h2>RazorPage のテスト</h2>
<p>
Name:ぺんぎんクッキー<br />
Price:110 <br />
Name:らくだキャラメル<br />
Price:85 <br />
</p>
</body>
</html>
@page
@model RazorPageTextTag.Pages.page1Model
@{
}
<html>
<head>
</head>
<body>
<h2>RazorPage のテスト</h2>
<p>
@for (int i = 0; i < 2; i++) {
<span>Name:</span> @Model.Items[i].name<br />
<span>Price:</span> @Model.Items[i].price <br />
}
</p>
</body>
</html>