I've used the Ajax helper to create several forms like the one below throughout my website, but for some reason this single form posts to the server twice when submitted. I can see the posts in the dev tools happening immediately that the form is submitted. The only difference between them is the first one has an additional header (X-Requested-With:XMLHttpRequest).
I've read through some answers on Stackoverflow suggesting that I might have duplicate requests for the jquery.unobtrusive file but I have checked the source and the dev tools and can only find a single instance. Nor can I find any other code which might be submitting the form.
If I remove the jquery.unobtrusive library then the form submits once but not as an AJAX request so the issue must lie somewhere with this library and how I've set up the form.
My view looks like this:
@using (Ajax.BeginForm("_Action", "Controller", null, new AjaxOptions
{
HttpMethod = "POST",
OnBegin = "beginFunc",
OnComplete = "completeFunc",
OnSuccess = "successFunc",
OnFailure = "failureFunc"
},
new { id = "form-id", @class = "loading-container" }))
{
@Html.AntiForgeryToken()
<div class="form-input">
@Html.EditorFor(m => m.PropertyName)
@Html.ValidationMessageFor(m => m.PropertyName)
</div>
<button type="submit" class="right-arrow">Submit</button>
}
My action looks like this:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult _Action(ViewModel vm)
{
// Method code goes here
}
In my BundleConfig.cs I have the following
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate.unobtrusive*", "~/Scripts/jquery.unobtrusive*"));
Can anybody offer any other suggestions of how to debug this or things I can check?