次のように、ユーザーが時間をテーブルに入力できるようにする必要があります。
モデル データを保持するために、次のクラスを宣言しました。
public class WeeklyTimes
{
public decimal Week1 { get; set; }
public decimal Week2 { get; set; }
public decimal Week3 { get; set; }
public decimal Week4 { get; set; }
public decimal Week5 { get; set; }
}
public class MonthlyReport
{
public WeeklyTimes TimeSpentTutoring { get; set; }
public WeeklyTimes TimeSpentOnPreparation { get; set; }
public WeeklyTimes TimeSpentOnHomework { get; set; }
}
そして、次のビューにバインドします。
<table class="timesheet">
<tr class="timesheet-row">
<th class="center-align" />
<th class="center-align">Week 1</th>
<th class="center-align">Week 2</th>
<th class="center-align">Week 3</th>
<th class="center-align">Week 4</th>
<th class="center-align">Week 5</th>
</tr>
<tr class="timesheet-row">
<th class="left-align">Tutoring Time</th>
<td>@Html.TextBoxFor(x => x.TimeSpentTutoring.Week1, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentTutoring.Week2, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentTutoring.Week3, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentTutoring.Week4, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentTutoring.Week5, new { @class = "input-time" })</td>
</tr>
<tr class="timesheet-row">
<th class="left-align">Learner Homework</th>
<td>@Html.TextBoxFor(x => x.TimeSpentOnHomework.Week1, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnHomework.Week2, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnHomework.Week3, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnHomework.Week4, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnHomework.Week5, new { @class = "input-time" })</td>
</tr>
<tr class="timesheet-row">
<th class="left-align">Tutor Prep & Commute</th>
<td>@Html.TextBoxFor(x => x.TimeSpentOnPreparation.Week1, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnPreparation.Week2, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnPreparation.Week3, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnPreparation.Week4, new { @class = "input-time" })</td>
<td>@Html.TextBoxFor(x => x.TimeSpentOnPreparation.Week5, new { @class = "input-time" })</td>
</tr>
</table>
この質問の 2 つの部分:
- 私は MVC を初めて使用し、HTML の重複の量について確信が持てません。この HTML を構造化するより良い方法はありますか?
- 適切な検証を確実にするための最良の方法は何ですか? 理想的には、ユーザーは「#.#」の形式の数字のみを入力できます。ただし、10 進数データ型を使用すると、これを実現できないようです。文字列データ型と正規表現の検証を使用することも検討していますが、それは奇妙に思えます。