KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using ASP.NET MVC2 and trying to validate my view models using the attributes in System.ComponentModel.DataAnnotations namespace. How can I dynamically set the permitted valid range of a RangeAttribute? For example, if I want to validate that a date entered is within an expected range. This doesn't compile: [Range(typeof(DateTime), DateTime.Today.ToShortDateString(), DateTime.Today.AddYears(1).ToShortDateString())] public DateTime DeliveryDate { get; set; } because "an attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type". Do I need to resort to creating my own custom validator?
Tags (comma-separated)
Save Edits
Cancel