【发布时间】:2011-08-01 01:18:14
【问题描述】:
ThingController 创建一个模型,其中包含(以及其他属性)事物的集合。这些可以像这样在视图中进行编辑:
<form action="@Url.Action("Update", "Thing")" method="post">
<table>
<tr>
<th>Foo</th>
<th>Bar</th>
</tr>
@foreach (var thing in ViewData.Model.Things)
{
<tr class="raw-data">
<td class="raw-data"><input name="things[@rowCount].Foo" class="raw-data" readonly="readonly" type="text" value="@thing.Foo" /></td>
<td class="raw-data"><input name="things[@rowCount].Bar" class="raw-data" type="text" value="@thing.Bar" /></td>
</tr>
rowCount++;
}
</table>
<br />
<input type="submit" value="OK" />
</form>
控制器包含以下动作,允许同时更新多个事物:
public ActionResult Update(ThingModel[] things)
{
...
}
我在 Thing 类的属性中添加了一些验证属性:
[Required]
[Range(0, 500000, ErrorMessage = "Foo must be within 0 and 500,000.")]
public double Foo{ get; set; }
[Required]
[Range(0, 500000, ErrorMessage = "Bar must be within 0 and 500,000.")]
public double Bar { get; set; }
问题是,我不知道如何使用 TextBoxFor 助手等添加不显眼的验证。
在这一点上,我认为正确的方法是使用验证属性手动标记输入字段,但我想知道是否有人可以向我指出一些文档、教程等,这些文档、教程等演示了帮助程序、多个模型的使用和不显眼的验证?
【问题讨论】: