I’m updating an old ASP.NET MVC application to use the 4.0 framework, and I’m not sure what to do with the custom ModelBinders. They extend Microsoft.Web.Mvc.DataAnnotations.DataAnnotationsModelBinder, which seems not to exist in 4.0, and they are registered in global.asax.
What is the best way to implement specific binding validation rules? Should I continue to use a custom model binder? If so, what is the default binder I should subclass (or perhaps decorate)? Or should I create custom validation attributes instead? Or something else?
Impossible to say without explaining what your application does and why was this custom model binder needed before.
The default model binder is:
System.Web.Mvc.DefaultModelBinderwhich implements theIModelBinderinterface but you rarely have to directly implement the interface when creating a custom model binder as the default model binder already contains lots of functionality.If you are doing validation you could indeed create validation attributes deriving from ValidationAttribute or some of the existing data annotations. Or if you are like me you could use FluentValidation.NET.
So, as you can see it will all depend.