whiteproud
whiteproud

Reputation: 95

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

Upvotes: 3

Views: 3351

Answers (1)

Amin Saqi
Amin Saqi

Reputation: 18977

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

Upvotes: 2

Related Questions