MVC client side validation not working with modal or Bootstrap model

Recently in my one of the MVC Project, dynamically loaded content on Bootstrap modal client side validation was not working. By any chance if you face same issue this post is important for you.

How to resolve

The form is not added to the page when the page loads, so the unobtrusive validation will not pick it up. There are two ways to fix this.

Way 1
Include the form on the page during the initial load. This will cause the form to be recognized and validation will occur. You can throw the partial view in a hidden div. Then your JavaScript will just show the modal dialog.

Way 2
Manually register the form with the unobtrusive validation after adding it to the page. Something like $.validator.unobtrusive.parse("#id-of-the-form");

Hope this helps.

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System