1
我已经构建了一个用于数据输入的Web应用程序(数据类型不重要)。该站点的一部分允许用户动态添加数据行。对于静态输入字段,我使用DataAnnotations以便我可以管理字段的验证。当我尝试为动态字段做类似的事情时,验证似乎不起作用。验证动态行
这是我的应用程序的(一般)设置。
[Data Input Page] -> [Partial Page for Dynamic Table] -> [Table is made up of individual rows (partial page)]
每个页面都是强类型的。
这里是一个独立的行的例子,部分页面:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.Person>" %>
<tr>
<% using (Html.BeginCollectionItem("People")) { %>
<td class="ui-widget-content"><%= Html.TextBoxFor(model => model.Name) %></td>
<td class="ui-widget-content"><%= Html.TextBoxFor(model => model.Age) %></td>
<td class="ui-widget-content"><%= Html.TextBoxFor(model => model.PhoneNumber) %>
// [Cut] Some other, unimportant information here which allows a new row to be added.
</tr>
// This portion is not working - it does work with static fields.
<div class="validation">
<div><%: Html.ValidationMessageFor(model => model.Name)%></div>
<div><%: Html.ValidationMessageFor(model => model.Age)%></div>
<div><%: Html.ValidationMessageFor(model => model.PhoneNumber)%></div>
</div>
任何洞察得到验证与DataAnnotations工作(所以它是相同/相似于什么我已经在做)会非常感激。
谢谢(并接受)。这确实回答了这个问题。但是,疯狂的黑客。 – JasCav 2011-01-18 21:15:50