Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Range date data annotation validation attribute c#

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

like image 448
whiteproud Avatar asked Jun 18 '26 06:06

whiteproud


1 Answers

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

like image 159
Amin Saqi Avatar answered Jun 19 '26 19:06

Amin Saqi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!