MVC 3 Make a change to an input id and still have the validation work? Multiple identical models in one view
I am attempting to have a multiple model input page where I have 4 iterations of a model in an input form. Problem here is that all of the inputs are given the same id/name in the html, so only the first set is validated. 开发者_高级运维With javascript, I was able to modify the ids/names of the inputs, but then all of the data-val- attributes are cleared out (or not initialized). Is there a way I can do this?
It is rendered inside the form like this:
foreach (LogEntry sub in entry.SubEntries)
{ @Html.Partial("_ViewSubRow", sub) }
But the ones that re made inside that partial don't seem to validate?
You need to tell the validation plugin to reload after changing the id's. Try calling this after you updated the input's IDs:
$.validator.unobtrusive.parse('#myForm'));
精彩评论