Multiple Row Validation on Field

Dec 1, 2009 at 3:40 PM

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.


<input type="text" ID="Amount_1" Name="Amount_1" value="1.00" />

<input type="text" ID="Amount_2" Name="Amount_2" value="1.75" />

<input type="text" ID="Amount_3" Name="Amount_3" value="2.75" />

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 simplfying the example. I need to have 3 discount's for each customer in 3 rows.

Heres some code:


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


<% int i = 0; %>

<% foreach( var item in Model.Discounts) { %> <tr> <td> Discount <%= i %> </td> <td> <%= Html.TextBox(String.Format("Amount_{0}", i ), item.Amount ) %></td></tr> <% } %>

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

</table> </form>
Html.ClientSideValidation<Discount>() %>

Here my metadata
    public partial class Discount
        public class DiscountMetaData
            [Required(ErrorMessage = " [Required] ")]
            public string Amount { get; set; }
Any ideas on how to get that to work ?


May 26, 2010 at 1:28 PM

using FluentValidator is probably your best bet.