问题
We have a partial view that contains a form with unobtrusive client validation enabled.
If we load the partial view using Html.Action, the validation works on the client side.
If when the user clicks a link we use JQuery to populate a div with the partial view , the client validation always returns true.
Any idea what is going on?
回答1:
You need to parse the new html to hook up the validation controls. You can do this using:
$.validator.unobtrusive.parse( $('.selector' ) );
where the selector returns the container holding the new HTML. This is what I use with tabbed interfaces.
来源:https://stackoverflow.com/questions/6061941/asp-mvc-unobtrusive-client-validation-always-returning-true