Reputation: 135
I have a collection of objects that I'm trying to display, however the span generated by the ValidationMessageFor does not include all the validation attributes:
<span class="field-validation-error">This field is required</span>
instead of:
<span class="field-validation-error" data-valmsg-replace="true" data-valmsg-for="Questions[0].SingleAnswer"></span>
This is how I'm generating the html:
<fieldset id="dr_profileUpdates">
@Html.EditorFor(model => model.Questions)
</fieldset>
And here is my editor template:
@Html.ValidationMessageFor(model => model.SingleAnswer)
@Html.TextBoxFor(model => model.SingleAnswer, new { @class = "textBoxDefault" })
The validation works, however the span does not dissapear after filling out the textbox and focusing out of it - I would assume this is because the span does not get generated correctly
Any help is appreciated.
EDIT: Actually it appears that after posting back to the server and returning the partial view (assuming the ModelState is invalid), those attributes do not get generated again - it only seems to affect the ValidationMessage. Any ideas?
Thanks,
Upvotes: 3
Views: 7153
Reputation: 36
Try add on top of your razor file
@{
Html.EnableUnobtrusiveJavaScript();
}
Upvotes: 1