Modal form submitting multiple times

By : Tappies
Source: Stackoverflow.com
Question!

My bootstrap modal is submitting multiple times, it appears to be for the amount of times the modal has been opened.

Code

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>

<script type="text/javascript">
// Close Modal when done.
function CloseModal() {
    $("#SkillModalWindow").modal("hide");
}
</script>

@using (Ajax.BeginForm("Save", "SkillGroup", null, new AjaxOptions
{
    HttpMethod = "Post",
    OnSuccess = "CloseModal"
},
new { id = "CreateSkillGroups" }))
{
@Html.ValidationSummary(true)
@Html.Hidden("JobRoleId", (int)ViewBag.JobRoleID)

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add New Skills to Job Role</h3>
</div>
<div class="modal-body" id="CreateModal">@Html.Partial("_Create")</div>
<div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button type="submit" class="btn btn-primary">Save</button>
</div>
}

Any Ideas?

By : Tappies


Answers

You are just hiding the modal, not resetting it. You need to reset the data after you post.

$('#SkillModalWindow').data('modal', null);


This video can help you solving your question :)
By: admin