I’m building an ASP.NET MVC application with a form that needs validation. The majority of the form is static, but part of the form is dynamic.
I need to enable the user to enter n string/date combinations.
The string/date combos need to be validated server side, and I need to give feedback to the user preferably directly beside the combination that failed validation.
For static input I do the following:
<%= Html.ValidationMessage('someField') %>
For the dynamic data, what should I do?
In your controller you’ll want to assign an error to the particular fields that fail validation:
Then all the helper is really doing is checking if the following exists:
and then creating a tag such as follows
the helper does a bit more null value checking but you get the idea.