Reputation: 1601
@using (Html.BeginForm("ExternalLoginConfirmation", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form"}))
{
@Html.AntiForgeryToken()
<br/>
<div class="form-group">
<div class="col-md-10">
@Html.HiddenFor(m => m.Email, new {@class = "form-control"})
@Html.HiddenFor(m => m.FirstName, new {@class = "form-control"})
@Html.HiddenFor(m => m.LastName, new {@class = "form-control"})
<input type="submit" class="btn btn-default btn-lg btn-success" value="Forsæt"/>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(".form-horizontal").submit();
</script>
}
Here is my form with the script I attempted. What I want is as soon as this view is being called and the form should be submitted automatically on page load. Is there a way to make it like this? Or even not go to the page and submit the form?
Upvotes: 0
Views: 32
Reputation: 5711
I think because your script loads before page fully loads. Try to wrap your submit action with
$(document).ready(function() {
$(".form-horizontal").submit();
})
Upvotes: 1