Asp MVC unobtrusive Client Validation always retur

2020-06-17 06:36发布

问题:

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.