views:

53

answers:

1

I'm using nhibernate validator in my current solution. Everythings is almost fine but...

My view model has a property of type Gender (see example below)

public virtual Gender Gender { get; set; }

public enum Gender { Female = 1, Male = 2 }

Now i like to have some validation to ensure that the gender property ist set. But neither the NotEmpty nor the NotNull Attribute fulfil the requirement.

Is there a kind of a generic solution or best practice to handle enum validations.

Thanks in advance.

+1  A: 

You can write a custom validator.

Here is a decent blog post about how to go about writing a custom validator.

Kevin Crowell
Well I saw that coming :-)
Herr W.