xVal 和验证多行数据

发布于 2024-08-12 21:28:06 字数 1400 浏览 7 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2024-08-19 21:28:06

我玩过一些前缀,这就是如何做到这一点:

首先,您必须命名文本框以具有不同的前缀,但具有相同的属性名称“Amount”,然后通过调用 Html.ClientSideValidation 将 jquery 验证器附加到每个字段每个前缀三次。

<form method="post" action="ProcessUpdate">

<table>

<tr> <td> Discount 1 </td> <td> <%= Html.TextBox("discount1.Amount") %></td></tr> 
<tr> <td> Discount 2 </td> <td> <%= Html.TextBox("discount2.Amount") %></td></tr>
<tr> <td> Discount 3 </td> <td> <%= Html.TextBox("discount3.Amount") %></td></tr>

<tr> <td> <input type="submit" value="submit"/> </td> </tr>

</table> 
</form> 

<%= Html.ClientSideValidation<Discount>("discount1") %>
<%= Html.ClientSideValidation<Discount>("discount2") %>
<%= Html.ClientSideValidation<Discount>("discount3") %>

希望这有帮助

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.

<form method="post" action="ProcessUpdate">

<table>

<tr> <td> Discount 1 </td> <td> <%= Html.TextBox("discount1.Amount") %></td></tr> 
<tr> <td> Discount 2 </td> <td> <%= Html.TextBox("discount2.Amount") %></td></tr>
<tr> <td> Discount 3 </td> <td> <%= Html.TextBox("discount3.Amount") %></td></tr>

<tr> <td> <input type="submit" value="submit"/> </td> </tr>

</table> 
</form> 

<%= Html.ClientSideValidation<Discount>("discount1") %>
<%= Html.ClientSideValidation<Discount>("discount2") %>
<%= Html.ClientSideValidation<Discount>("discount3") %>

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文