Tacud Tacud -4 years ago 117
ASP.NET (C#) Question

Fluent Validation overloaded (Less)GreaterThanOrEqualTo method doesn't render the same result

I'm using FluentValidation library and I'm trying to figure out why this:

this.RuleFor(m => m.Quantity).GreaterThanOrEqualTo(10);


renders this:

<input data-val-range-min="10" id="Quantity" name="Quantity" type="text" value="10"">


but the overloaded version of the same method:

this.RuleFor(m => m.Quantity).GreaterThanOrEqualTo(m => m.QuantityMin);


renders this (data-val-range-min is empty):

<input data-val-range-min="" id="Quantity" name="Quantity" type="text" value="10"">


I tested it a little bit and when I changed the code to something like this:

this.RuleFor(m => m.Quantity).GreaterThanOrEqualTo(m => this.GetMin(m));

function GetMin(ConfigurationView view)
{
return view.QuantityMin;
}


and set breakpoint inside the function, it won't stop there when I'm debugging. It won't go to the function at all. Does it mean that the Expression parameter doesn't compile and that's why the HTML attribute is empty? And why?

I know that the LessThanOrEqualTo and GraterThanOrEqualTo don't support client validation - or at least they didn't. All the articles I found are couple years old and maybe it's not the case anymore? Anyway, I don't really care about the client validation, just the data attribute. And I'd like to know the reason why one version of the same method doesn't render the value in HTML.

Thank you.

Answer Source

I contacted the author of FluentValidation and basically this feature is not implemented and it's hard to implement so that it's reliable. I believe it's possible to but I understand author's arguments not to do it: https://github.com/JeremySkinner/FluentValidation/issues/428

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download