I want to implement a Data annotation attribute to validate dates. I know something similar already exists like
[Range(typeof(DateTime), "1/2/2004", "3/4/2004", ErrorMessage = "Value for {0} must be between {1} and {2}")]
But this code obliges me to set a static data. Instead I would like to set the name of a textbox that contains a data.
This will be the html code
<input type="text" name="startdate" />
<input type="text" name="enddate" />
and this the C# code
public class event {
public ....
[Range(DateTime.Today, "enddate")]
public startdate {set;get;}
[Range("startdate", "01/01/2014")]
public enddate {set;get;}
}
Somebady can help me with the code? thanks
Yeah definitely. However not by standard data annotations.
Install foolproof nuget package and use its extra useful attributes! Examples of exactly what you need are here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With