Inheritence

Jun 11, 2010 at 10:34 AM
Edited Jun 11, 2010 at 10:35 AM

Hi,

I downloaded and used the MVC foolproof validation module and it works great as far as I could tell.

But I encountered an issue when I tried to create another class that inherited RequiredIfNotEmptyAttribute. Even though I didn't write any code to my class except the constructor that inherited base(string) whenever I used it it threw System.NotImplementedException.
From what I could figure out, the new class ends up calling IsValid(object value) instead of IsValid(object value, object dependentValue, object caontainer).

Can you help me with this?

Coordinator
Jun 11, 2010 at 12:45 PM
Edited Jun 11, 2010 at 12:46 PM

Hello Doly. You need to register your new Attribute with Foolproof. I usually do this in the new Attribute's static constructor:

static MyNewAttribute() { Register.Attribute(typeof(MyNewAttribute)); }

 

Coordinator
Jun 11, 2010 at 12:47 PM

Also, here is a blog post where I create a custom foolproof validator:

http://www.nickriggs.com/posts/build-model-aware-custom-validation-attributes-in-asp-net-mvc-2/