0

in my Edit View i need the user to type in start date and end date of a test release. Now i have to make sure that the user gets an error message if he wants to save the enddate before startdate. e.g. start date 01.02.12 and enddate 01.01.2013!

Any Ideas?

1 Answer 1

2

The quick and dirty (sort-of) way - add the following code in your controller method:

if (data.StartDate > data.EndDate)
    this.ModelState.AddModelError("EndData", "End date must be after the start date.");

if (!this.ModelState.IsValid)
    return this.View();

A better (or cleaner) solution would be to create a custom validation attribute for the model. An example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.