验证动态行
我已经构建了一个用于数据输入的网络应用程序(数据类型并不重要)。该站点的一部分允许用户动态添加数据行。对于静态输入字段,我使用 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 进行验证的见解(因此它与我已经在做的事情相同/相似)将不胜感激。
I have built a web application for data input (the type of data is unimportant). One portion of this site allows the user to dynamically add rows of data. For the static input fields, I use DataAnnotations so that I can manage validation of the fields. When I attempt to do a similar thing for the dynamic fields, validation does not appear to work.
Here is the (general) setup of my application.
[Data Input Page] -> [Partial Page for Dynamic Table] -> [Table is made up of individual rows (partial page)]
Each page is strongly typed.
Here is an example of an individual row, 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>
Any insight into getting validation to work with DataAnnotations (so it is the same/similar to what I'm already doing) would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Steve Sanderson 发表博客在这种情况下进行验证。
Steve Sanderson blogged about validation in this case.