When you create a view with a submit button, the default behavior is submit will be triggered on KEY PRESS events.
If your view has a BeginForm, following code will stop submitting on KEY PRESS.
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { onkeydown = "return event.keyCode!=13" }))
{
//code
}
Alternatively you can use jQuery to resolve the same issue as follows
<script>
$(function () {
$(document).on("keydown", "input", function(e) {
if (e.which==13) e.preventDefault();
});
});
</script>
If your view has a BeginForm, following code will stop submitting on KEY PRESS.
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { onkeydown = "return event.keyCode!=13" }))
{
//code
}
Alternatively you can use jQuery to resolve the same issue as follows
<script>
$(function () {
$(document).on("keydown", "input", function(e) {
if (e.which==13) e.preventDefault();
});
});
</script>