Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Validation Dynamically Added Rows

$
0
0
Hi Jeremy,

What I was trying to say is that I have 10 rows with 3 columns each. (I have the HTML table already created (hard coded) in my view)

I use a dropDown field with values from 1 to 10. Depending on the value I hide/display rows. (If user select 3 from the dropdown, then only 3 rows will be displayed)

Now I want to validate only the rows that are displayed and I know this by the value selected in the dropDown.

DorpDown = NumberRows (see below) is of type string, not sure if it matters?

RuleFor(x => x.Name1).Must(y=> y.NumberRows).GreaterThanOrEqual(1);
RuleFor(x => x.City1).Must(y=> y.NumberRows).GreaterThanOrEqual(1);
RuleFor(x => x.State1).Must(y=> y.NumberRows).GreaterThanOrEqual(1);

RuleFor(x => x.Name2).Must(y=> y.NumberRows).GreaterThanOrEqual(2);
RuleFor(x => x.City2).Must(y=> y.NumberRows).GreaterThanOrEqual(2);
RuleFor(x => x.State2).Must(y=> y.NumberRows).GreaterThanOrEqual(2);

RuleFor(x => x.Name3).Must(y=> y.NumberRows).GreaterThanOrEqual(3);
RuleFor(x => x.City3).Must(y=> y.NumberRows).GreaterThanOrEqual(3);
RuleFor(x => x.State3).Must(y=> y.NumberRows).GreaterThanOrEqual(3);

and so on.

I get a bunch of error message that I can add if you would like.

Would you mind directing me in the right direction?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>