views:

19

answers:

1

Has anyone extended the Range attribute to be able to have a variable range?

I have a similar need but I can't make this work:

public class YearRangeAttribute : RangeAttribute
    {
        public YearRangeAttribute()
            : base(typeof(DateTime), DateTime.Now.AddYears(-100).Year.ToString(), DateTime.Now.AddYears(-14).Year.ToString()) { }

    }

There is nothing on the page when it is rendered to the browser.

Any ideas?

TIA

A: 
# public class YearRangeAttribute : RangeAttribute  
#    {  
#          
#   
#   
#        public YearRangeAttribute()  
#           : base(DateTime.Now.AddYears(-100).Year, DateTime.Now.AddYears(-16).Year) { }  
#                 
#          
#              
#    }

and on the Global.asax.cs:

   DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(YearRangeAttribute), typeof(RangeAttributeAdapter));  

Cheers

Lizet

Lizet
I got the answer on another forum
Lizet