FluentValidation icon indicating copy to clipboard operation
FluentValidation copied to clipboard

[Question] <ValidationMessage For="..."> when validating the whole object using Must

Open abbottmw opened this issue 7 months ago • 1 comments

I have a complex validation so I am using the Must() method on the FluentValidation call. This may have an easy answer, but when I use <ValidationMessage For="myobject">, the error messages above each question do not show up. Is there a way to make the ValidationMessage component work with a whole object and not a property?

I have a Rule like

RuleFor( r => r).Must(ValidateObject).WithMessage("custom error messsage");

but not sure how to get that message to show up using the <ValidationMessage/> component. Do I need to create another property in my class that the ValidationMessage can use?

Thanks

abbottmw avatar Dec 04 '23 19:12 abbottmw

So, I got the validation to work restructuring how I setup the validations. Chained some When() calls to handle the different kinds of validation based on a property. I started creating dependant rules, but changed those to When().

abbottmw avatar Jan 09 '24 13:01 abbottmw