1

I want to restrict user from entering a date except a particular range in my MVC 4 application. Please suggest how can I do this.

atul
  • 561
  • 4
  • 12
  • what have you tried so far? what validation framework are you using? are you validating on the client, server or both? – Jason Meckley May 03 '13 at 12:09
  • You have to implement self validated class. Use IValidatableObject and take a look here http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx – NoWar May 03 '13 at 12:10
  • This link will be helpful for date range validation http://stackoverflow.com/questions/13183647/date-range-validation-with-entity-framework-4-data-annotations – Nikhil Gaur May 03 '13 at 12:15
  • @JasonMeckley: I have to implement on both server as well as client. I have implemented server side validation by inheriting my class 'DateRangeAttribute' with 'ValidationAttribute' class and it is working fine. But I need it on client side also. So is there a inbuilt or predefined approach to do this? – atul May 03 '13 at 12:15
  • @Nikhil: Thanks for your reply, but I have already tried this and it is not working for me. – atul May 03 '13 at 12:16
  • 1
    You should state in your question that you have implemented server-side validation, and that you need to implement client-side validation. Otherwise, people will see the C# tag and automatically think server-side. – CM Kanode May 03 '13 at 12:30
  • http://stackoverflow.com/questions/3761185/jquery-validate-date-range – CM Kanode May 03 '13 at 12:31

1 Answers1

0

You can implement IValidatableObject interface and using Validate method to do this validation.

check Using IValidatableObject Custom Validation

Amit Rai Sharma
  • 4,015
  • 1
  • 28
  • 35