I have a page that I want to have a list of items (header items) with some details and a link to view and a link to edit them. In addition at the top of the list I want to have a form to get the basic details (start and end date) and create a new header item using that data.
What I've done:
- created a header controller
- created an index view (gets list of items)
- created a startHeader view (has a form with start, end date and a button, form has an actionName of "addHeader")
- added the "ValidationMessageFor" for the start and end date
- added the startHeader view as a partial view to the index view
Everything generally appears to be working except for some validation. The required field validation appears to be working as expected (i.e. if you don't put in a start date and click the button it says "Start Date is required").
However I've added some additional validation that doesn't appear to be working:
- added IValidatableObject interface to the header class
added validation code
if (this.StartDate > this.EndDate) { yield return new ValidationResult("Start Date must be prior to End Date.", new[] { "StartDate" }); }
- when the button is pressed this code runs as expected
- however it doesn't stay on the index screen and display the validation message
- rather it goes through to the addHeader view
- i had expected this to work the same as the required field validation and display the validation message
Is there something I'm missing here?
- why is this validation running, but not displaying the error message?
- do i need to add something to get this validation to run and remain on the page?
- is there a better method of doing something like this?