I have Edit form page where if user make any changes then all the changes appear in the Modal popup. For that, I have used Jquery to fire Modal. In the Modal popup, the submit button is not getting fired. If i Put the button in the page then it works fine. I do not have any idea where i am getting wrong. Any suggestion and guidance will be useful to me.
My .cshtml code:
@model TestProject.Models.Test
@using (Html.BeginForm())
{
<div class="form-horizontal" >
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.FName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FName, new { htmlAttributes = new { @class = "form-control",@id = "FName" } })
</div>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary" id="btnSubmit" data-toggle="modal" data-target="ListofChanges">Next</button>
</div>
</div>
}
My JavaScript Code inside .cshtml:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
var FirstName = "@Html.Raw(ViewBag.FName)";
$(document).ready(function () {
$("#btnSubmit").click(function () {
if ($("#FName").val() != FirstName)
{
$("#error").html("First Name changed from:" + FirstName);
}
$('#ListofChanges').modal("show");
});
});
</script>
My Modal to popup the changes:
<div id="ListofChanges" tabindex="-1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">PhoneBook Details changed from</h4>
</div>
<div class="modal-body">
<p id="error"></p>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" />
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Please guide me why submit button in not fired once clicked. Thank you in advance.
type="button". Change that totype="submit"if you want a submit button. Bootstrap's modal function is also asynchronous, so you need to prevent the form submission as well.