2

...or should I say, what's the cleanest way to use Enterprise Library 5 VAB with MVC?

I currently use the form:

ActionResult Save(int id, FormCollection form)
{
   SomeModel model = somehowgetbyid(id);

   UpdateModel(model);

   somehowvalidate(model);

   if(ModelState.IsValid)
   {

etc...

Can VAB decorated classes be validated automagically by updatemodel, or do I get the validator manually and validate it after that call? Or are there even better ways?

Carl R
  • 8,104
  • 5
  • 48
  • 80

2 Answers2

1

Here you have nice example of creating a ModelValidatorProvider with Enterprise Library VAB (by Brad Wilson):

It will allow you to use it in any way you want (implicit validation of action parameters or explicit calls to UpdateModel/TryUpdateModel)

tpeczek
  • 23,867
  • 3
  • 74
  • 77
0

It seems that I didn't need to do anything. MVC picks up the VAB attributes by itself. This is for Enterprise Library 5.0.

Wow!

Carl R
  • 8,104
  • 5
  • 48
  • 80
  • Yep. That's because the VAB attributes inherit from the base validation attribute of DataAnnotations. MVC natively works with DataAnnotations attributes. – Steven Apr 18 '11 at 10:25
  • An observation I've made is that if there are rulesets involved, the default ruleset isn't invoked. It just makes the modelbinder skip the validation attribute. – Carl R May 12 '11 at 11:06