ASP.Net Core MVC Validations are not working , after added a click event in the submit button
I added a click event in the submit button to display a confirmation message:
$("#btnSubmit").click(function () {
alert("An event is clicked");
});
That broke all client-side validations of ASP.Net Core MVC, however, the server side validations is still working. You cannot submit an event with invalid data, but it won't display the errors messages.
I tried to add the javascript code in the submit event in form instead of the click event of the event, that is not working too. Even I added another invisible submit button, after the confirmation message is displayed, then the code will trigger the click event of that invisible submit button. That is still not working.
I randomly placed the script tags. I found the script file which contains the click event needs to place after the validation scripts:
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script><script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 266 feedbacks awaiting moderation...
Form is loading...