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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.