Posted
about 11 years
ago
by
kf78
I see where I got confused. Apparently there's another product out there that uses and extends FluentValidation. This is the document I was looking at: https://github.com/ServiceStack/ServiceStack/wiki/Validation
Thanks for the speedy reply! I'll try to read online examples more carefully in the future. :)
|
Posted
about 11 years
ago
by
JeremyS
Hi
This isn't actually a feature that's ever existed. I'm curious where you saw it, because I don't remember ever having heard of this idea before.
Anyway, you could probably implement it by using a custom IValidatorInterceptor implementation.
|
Posted
about 11 years
ago
by
kf78
I see references to an ApplyTo flags to define different RuleSets for different HTTP methods back in version 3, but I don't seem to see any corresponding functionality in the current version. Did this go away? Is there a better/easier way to do this?
Thanks!
|
Posted
about 11 years
ago
by
MotoWilliams
Happy to help if/once I understand how to do it. Being able to use FV with MVC & Web Api with a container seems like it would a common use-case for a lot of folks.
|
Posted
about 11 years
ago
by
JeremyS
So at the moment it isn't really possible in this way. RuleSets cascade down to child validators, but you can't explicitly choose a ruleset to execute. I really like this idea though, so if you could create an issue for this on the issue tracker I'll try and add it for a future release.
Jeremy
|
Posted
about 11 years
ago
by
JeremyS
Hi
No. Validators are completely separate from mvc, and have no knowledge of any mvc-specific items such as controllers or tempdata. The only thing that the validator sees is the object being passed to it for validation, so you could copy the items
|
Posted
about 11 years
ago
by
gadd68
Thanks Jeremy, think I finally figured it out, making sure it only runs if fields are not empty/null
RuleFor(x => x.ExpireYear).Must(x => Convert.ToInt32(x) >= DateTime.Now.Year).When(f =>
|
Posted
about 11 years
ago
by
pauljame
Hello
Is it possible to access controller TempData in a Validator ?
Thanks
|
Posted
about 11 years
ago
by
JeremyS
Hi
A call to RuleFor should reference a property directly. You can't call Convert.ToInt32 from within a rule definition.
You'll either need to 1) change the data type of your ExpireMonth and ExpireYear properties to be ints. or 2) Use a custom
|
Posted
about 11 years
ago
by
gadd68
Hi, I'm new to Fluent Validation. I know I should be able to do this, and have looked up lots of other posts but just can't figure it out.
ExpireMonth and ExpireYear are strings
This bit works fine
RuleFor(x =>
|