0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【保険商品管理システムの開発】生命保険処理のViewsを作成・確認

Posted at

Viewsとは

RazorやASP.NET Core MVCでいう 「View(ビュー)」 とは、簡単に言うと ユーザーに表示する画面のテンプレート のことです。

Views フォルダを作成

Views/LifeInsuranceMvc の中に以下の Razor ビュー (.cshtml) を置きます。

コード

Views/LifeInsuranceMvc/Customers.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>
Views/LifeInsuranceMvc/ActivePolicies.cshtml
@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>
Views/LifeInsuranceMvc/TotalPremium.cshtml
@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
スクリーンショット 2025-09-01 8.18.20.png

以下URLは、データが取得できていないので、要修正。

契約一覧 → https://localhost:7252/LifeInsuranceMvc/ActivePolicies?customerId=CUST001
スクリーンショット 2025-09-01 8.20.17.png

合計保険料 → https://localhost:7252/LifeInsuranceMvc/TotalPremium?customerId=CUST001
スクリーンショット 2025-09-01 8.21.14.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?