課題05(7/8)
注意
- 以下の設問はリアクションペーパーに「課題05」という節を設けて, 課題名の見出しを付けて 回答すること.
- これらはすべて課題点として成績に算入される課題である.
【課題5-07】ビューの記述方法の理解1
【課題5-04】のアプリケーションには,表5-5-1のWidget
クラスの中身を 表示 するための
ビューが存在する.このビューのための .cshtml ファイルの記述を_に示す.これについて
以下の問いに回答せよ.
- Q1. 14行目,20行目には
@Html.DisplayNameFor(...)
という記述が含まれているがこれは何のためのものか説明せよ. - Q2.
@Html.DisplayNameFor(...)
とフォームで使用する <label asp-for="..."></label>
との違いを説明せよ(必要に応じて調査も行うこと).
Widgetクラスの表示のためのRazorビュー(.cshtml) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| @model Widget
@{
ViewData["Title"] = "Widgetの表示";
if (Model is null) throw new ArgumentNullException(nameof(Model)); // ad-hoc! 非null保証のための回避策
}
<table>
<tr><th>項目</th><th>値</th></tr>
@* IDの表示 *@
<tr>
<td>@Html.DisplayNameFor(w => w.Id)</td>
<td>@Html.DisplayFor(w => w.Id)</td>
</tr>
@* ラベルの表示 *@
<tr>
<td>@Html.DisplayNameFor(w => w.Label)</td>
<td>@Html.DisplayFor(w => w.Label)</td>
</tr>
@* ..略.. *@
</table>
|
Last updated on 2024-05-10
Published on 2024-05-10