In my ASP.NET Core 2.0 project, I am utilizing the form tag for submission purposes. I am now looking to incorporate client-side validation for my form submission. To achieve this, I have included the onsubmit
attribute in my form tag as shown below:
<form id="formId" asp-action="ActionName" onsubmit="validationFunction(Event)">
Additionally, I have created a function like this:
function validationFunction(e) {
//CheckStuff
e.preventDefault();
}
However, despite triggering the function properly, neither e.preventDefault()
nor return false
seem to prevent the submission process.
How can I successfully prevent my form submission from going through?
PS. I am aware that I could handle this scenario by managing the button click and submitting the form only after validation is complete. Nonetheless, I am curious as to why the above approach does not work in ASP.NET Core or if there is something I am overlooking.