【发布时间】:2017-11-15 21:44:43
【问题描述】:
我有Edit 表单页面,如果用户进行任何更改,那么所有更改都会出现在Modal 弹出窗口中。为此,我使用Jquery 触发Modal。在Modal 弹出窗口中,submit button 没有被解雇。如果我将按钮放在页面中,那么它可以正常工作。我不知道我哪里出错了。任何建议和指导都会对我有用。
我的.cshtml 代码:
@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>
}
我的JavaScript 里面的代码.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>
我的Modal 弹出更改:
<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>
请指导我为什么单击后提交按钮未触发。提前谢谢你。
【问题讨论】:
-
另外值得指出的是,btnSubmit 不是提交按钮 - 你使用了
type="button"。如果您需要提交按钮,请将其更改为type="submit"。 Bootstrap 的 modal 功能也是异步的,所以你也需要阻止表单提交。
标签: jquery asp.net-mvc twitter-bootstrap