xVal 和验证多行数据
我有一个名为 Discount 的表,其架构如下:
PK DiscountID int
FK CustomerID int
Amount Money
Name varchar(50)
因此,我显示与客户相关的所有折扣。每个顾客都会有3条折扣记录。
当我生成表单时,用于编辑的关联文本框的 ID 和名称必须是唯一的才能正确处理。
示例
当我尝试使用 xVal 进行验证时,由于我的字段名称与架构名称“Amount_1”而不是“Amount”不匹配,因此它不会验证该字段。
我怎样才能让它发挥作用?
我无法将所有 3 个折扣合并到唯一客户的一条记录中,因为为了简化示例,我省略了一些其他字段。我需要为 3 行中的每个客户提供 3 个折扣。
这是一些代码:
<form method="post" action="ProcessUpdate">
<table>
<tr> <td> Discount 1 </td> <td> <%= Html.TextBox("Amount_1") %></td></tr>
<tr> <td> Discount 2 </td> <td> <%= Html.TextBox("Amount_2") %></td></tr>
<tr> <td> Discount 3 </td> <td> <%= Html.TextBox("Amount_3") %></td></tr>
<tr> <td> <input type="submit" value="submit"/> </td> </tr>
</table>
</form>
<%= Html.ClientSideValidation<Discount>() %>
这是我的元数据
[MetadataType(typeof(DiscountMetaData))]
public partial class Discount
{
public class DiscountMetaData
{
[Required(ErrorMessage = " [Required] ")]
public string Amount { get; set; }
}
}
有关如何使其发挥作用的任何想法吗?
I have a table name Discount that has the following schema:
PK DiscountID int
FK CustomerID int
Amount money
Name varchar(50)
So I am displaying all the discounts related to the customer. Each customer will have 3 discount records.
When I generate the form the ID's and Name's of the associated textboxes for editing that have to be unique to process correctly.
Example
When I try to validate using xVal, since my field names are not matching the schema name, 'Amount_1' instead of 'Amount', it doesn't validate the field.
How can I get this to work ?
I cant combine all 3 discounts into one record for the unique customer, since there is some other fields i left out for simplifying the example. I need to have 3 discount's for each customer in 3 rows.
Here's some code:
<form method="post" action="ProcessUpdate">
<table>
<tr> <td> Discount 1 </td> <td> <%= Html.TextBox("Amount_1") %></td></tr>
<tr> <td> Discount 2 </td> <td> <%= Html.TextBox("Amount_2") %></td></tr>
<tr> <td> Discount 3 </td> <td> <%= Html.TextBox("Amount_3") %></td></tr>
<tr> <td> <input type="submit" value="submit"/> </td> </tr>
</table>
</form>
<%= Html.ClientSideValidation<Discount>() %>
Here my metadata
[MetadataType(typeof(DiscountMetaData))]
public partial class Discount
{
public class DiscountMetaData
{
[Required(ErrorMessage = " [Required] ")]
public string Amount { get; set; }
}
}
Any ideas on how to get that to work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我玩过一些前缀,这就是如何做到这一点:
首先,您必须命名文本框以具有不同的前缀,但具有相同的属性名称“Amount”,然后通过调用 Html.ClientSideValidation 将 jquery 验证器附加到每个字段每个前缀三次。
希望这有帮助
I've played a bit with prefixes and this is how this could be done:
First you would have to name textboxes to have deferent prefix, but same property name "Amount" and then to attach jquery validators to each field by calling Html.ClientSideValidation three times, for each prefix.
Hope this helps