In a MVC view, I have a form as below. when user click on the submit button, I want to check somthing firstly. If it is ok, submit the form. If not pass the checking, give user a alert message, then stay in the view. My sample code as:
<script type="text/javascript">
function CheckingStatus() {
//.....
if (answer == "N") {
alert("You choose No.");
return false;
}
}
</script>
<% Html.RenderPartial("MyForm"); %>
....
<input id="btnSubmit" type="submit" value="Submit" onclick="CheckingStatus();" />
<% } %>
But when testing, even answer=="N", the form is still submitted. How to stop the form submitting ?