FluentValidation v3: Other features
25 Jun 2011
using System.DraggyDroppy;
25 Jun 2011
This is part 6 in a series of posts about the new features in FluentValidation v3.
In addition to the major new features I’ve already posted about, there are several other smaller features available in FluentValidation v3:
FluentValidation will now automatically infer the display name for properties annotated with the DisplayAttribute/DisplayNameAttribute.
Localized error messages now support custom format arguments in the same way as non-localized messages.
FluentValidation v3 allows rules to be defined for child properties within the top level validator:
RuleFor(x => x.Address.PostalCode).NotNull();
In previous versions of FluentValidation, the property name would always be generated as “PostalCode” instead of “Address.PostalCode”, and you’d have to rely on a child validator which in some situations isn’t desirable.
Support for client side error messages has been slightly expanded. The following rules are now supported on the client:
In addition, the client-side error messages for several validators have been improved so they no longer rely on FluentValidation’s named placeholders when running on the client.
If you’re using rulesets alongside ASP.NET MVC, then you’ll notice that by default FluentValidation will only generate client-side error messages for rules not part of any ruleset. You can instead specify that FluentValidation should generate clientside rules from a particular ruleset by attributing your controller action with a RuleSetForClientSideMessagesAttribute:
[RuleSetForClientSideMessages("MyRuleset")] public ActionResult Index() { return View(new PersonViewModel()); }
…plus several bug fixes.