是否有一种干净简单的方法来表示在剃刀视图中具有数据库模型列表的视图模型?
我目前能够让这个工作,但我必须为我的输入的每个id和名称提供一个唯一值,然后循环通过formcollection
尝试匹配输入的id / name到检索数据。
有更简单/更清洁的方法吗?
@model WorkedHoursEditorViewModel
@section header {
<h1>@Resources.Global.Label_WorkedHours</h1>
<a href="#" id="header-save" class="ui-btn-right">@Resources.Global.Label_Save</a>
}
@using (Html.BeginForm(
"EditReportWorkedHours",
"Order",
FormMethod.Post,
new Dictionary<string, object>
{
{"id", "detail-form"},
{"class", "ui-body ui-corner-all"},
{"data-ajax", "false"}
}))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(q => q.Report.Id)
<div data-role="collapsible-set" data-inset="false" data-theme="c" data-content-theme="d" style=" margin:0;">
@foreach (var item in @Model.WorkDayList)
{
<div data-role="collapsible" data-collapsed="false">
<h3>@item.Date.DayOfWeek @item.Date.Year-@item.Date.Month-@item.Date.Day</h3>
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<label for="Hours.@item.Date.Day">@Resources.Global.Label_Hours:</label>
</div>
<div class="ui-block-b">
<input type="text" id="Hours_@item.Date.Day" name="Hours.@item.Date.Day" value="@item.Hours" />
</div>
<div class="ui-block-a">
<label for="Charged.Hours.@item.Date.Day">@Resources.Global.Label_ChargedHours:</label>
</div>
<div class="ui-block-b">
<input type="text" id="Charged_Hours_@item.Date.Day" name="Charged.Hours.@item.Date.Day" value="@item.Charged" />
</div>
<div class="ui-block-a">
<label for="Travel.Hours.@item.Date.Day">@Resources.Global.Label_TravelHours:</label>
</div>
<div class="ui-block-b">
<input type="text" id="Travel_Hours_@item.Date.Day" name="Travel.Hours.@item.Date.Day" value="@item.Travel_Hours" />
</div>
</fieldset>
</div>
}
</div>
}
答案 0 :(得分:0)
这是一篇关于模型绑定和列表的好文章:http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/