I have to call a js function before asp-action is called on button click
<form asp-action="Index" method="post">
@Html.AntiForgeryToken()
var x = jsfunction();
<div class="form-group">
<input type="submit" value=@Localizer["Button"] class="btn Button" />
</div>
</form>
I want to call the js funtion on click of the submit button and then it should proceed to the controller action method
You can try as follow :
<form id='myForm' asp-action="Index" method="post">
@Html.AntiForgeryToken()
var x = jsfunction();
<div class="form-group">
<input id='submitBTN' type="button" value=@Localizer["Button"] class="btn Button" />
</div>
</form>
And call it's click event by jquery or js"
<script>
$('#submitBTN').on('click', function () {
jsfunction();
$('#myForm').submit();
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With