So i have these 2 input fields Fromdate and ToDate,
In MVC I want to create a CustomAttribute to ensure Fromdate is before ToDate.
Is this possible? if so how? or what is the alternative?
Thanks
MVC FoolProof Validation is a great way to go about this. It operates on the server side with a reference and also propagates client side with a script include.
http://foolproof.codeplex.com/
Here is an example of an attribute in action:
public class EventViewModel
{
[Required]
public string Name { get; set; }
[Required]
public DateTime Start { get; set; }
[Required]
[GreaterThan("Start")]
public DateTime End { get; set; }
}
See the GreaterThan Attribute on the date. This would save you having to write it all yourself.
You can also nuGet it into your project: http://nuget.org/packages/foolproof
PM> Install-Package foolproof
I hope this helps.
There are lots of validation attributes available in MVC 3 but sometimes we may require specific type of validation which is dependent on some other properties as well. The example in question isI come across a situation where I need validation on a set of checkboxes. Validation I need was simple that at least one checkbox from the set must be checked, so he is applying to more than one field, yes. He is checking if at least one of 3 checkboxes is checked.