Viewsとは
RazorやASP.NET Core MVCでいう 「View(ビュー)」 とは、簡単に言うと ユーザーに表示する画面のテンプレート のことです。
Views フォルダを作成
Views/LifeInsuranceMvc の中に以下の Razor ビュー (.cshtml) を置きます。
コード
@model IEnumerable<InsuranceProductManager.Models.Customer>
<h2>顧客一覧</h2>
<table class="table">
<thead>
<tr>
<th>顧客ID</th>
<th>名前</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach (var customer in Model)
{
<tr>
<td>@customer.CustomerId</td>
<td>@customer.Name</td>
<td>@customer.Email</td>
</tr>
}
</tbody>
</table>
@model IEnumerable<InsuranceProductManager.Models.InsurancePolicy>
<h2>顧客 @ViewBag.CustomerId の有効契約一覧</h2>
<table class="table">
<thead>
<tr>
<th>契約ID</th>
<th>プラン名</th>
<th>保険料</th>
<th>保障額</th>
</tr>
</thead>
<tbody>
@foreach (var policy in Model)
{
<tr>
<td>@policy.PolicyId</td>
<td>@policy.PlanName</td>
<td>@policy.Premium</td>
<td>@policy.CoverageAmount</td>
</tr>
}
</tbody>
</table>
@model decimal
<h2>顧客 @ViewBag.CustomerId の合計保険料</h2>
<p><strong>@Model 円</strong></p>
@ model
@ model は ASP.NET Core MVC / Razor Pages で「ビューに渡すモデルの型」を定義するためのディレクティブです。
@ model の後には 任意の .NET 型 を指定できます。
つまり「組み込みの基本型」「クラス」「コレクション」「匿名型以外の型」など、ほとんど使えます。
URLアクセス確認
顧客一覧 → https://localhost:7252/LifeInsuranceMvc/Customers

以下URLは、データが取得できていないので、要修正。
契約一覧 → https://localhost:7252/LifeInsuranceMvc/ActivePolicies?customerId=CUST001

合計保険料 → https://localhost:7252/LifeInsuranceMvc/TotalPremium?customerId=CUST001
