我有以下表格,这是一种自助表格。当验证错误发生时,我会看到出现的验证错误。但是当我关闭模态时,我想清除摘要。我怎么能这样做?。
@using (Html.BeginForm("Index", "Home", null, FormMethod.Post, new { Id = "frmSendEmail", @class = "form-horizontal" }))
{
<div class="modal fade" id="modalSendEmail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="modalLabel">Email</h4>
</div>
<div class="modal-body">
@Html.ValidationSummary(false, "Oops! Seems like we are missing the following details:", new { @class = "alert alert-danger" })
<div class="form-group">
<label for="txtName" class="col-sm-2 control-label">* Name:</label>
<div class="col-sm-10">
@Html.TextBoxFor(model => model.SenderName, null, new {id = "txtName", @class = "form-control", placeholder = "Name"})
</div>
</div>
<div class="form-group">
<label for="txtEmail" class="col-sm-2 control-label">* Email:</label>
<div class="col-sm-10">
@Html.TextBoxFor(model => model.SenderEmail, null, new { id = "txtEmail", @class = "form-control", placeholder = "Email", type = "email" })
</div>
</div>
<div class="form-group">
<label for="txtTelephone" class="col-sm-2 control-label">Telephone:</label>
<div class="col-sm-10">
@Html.TextBoxFor(model => model.SenderTelephone, null, new { id = "txtTelephone", @class = "form-control", placeholder = "Telephone" })
</div>
</div>
<div class="form-group">
<label for="txtEnquiry" class="col-sm-2 control-label">* Enquiry:</label>
<div class="col-sm-10">
@Html.TextAreaFor(model => model.SenderEnquiry, new { id = "txtEnquiry", @class = "form-control", rows = "5" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="btnCloseSendEmail">Close</button>
<button type="submit" class="btn btn-warning" id="btnSendEmail">Send</button>
</div>
</div>
</div>
</div>
}
答案 0 :(得分:0)
使用hidden.bs.modal
事件检测模态关闭。这个validation-summary-errors
是为验证错误div添加的类。所以你可以删除它,清空它或根据你的要求隐藏它。
$('#modalSendEmail').on('hidden.bs.modal', function (e) {
$('.validation-summary-errors').remove()
//or
//$('.validation-summary-errors').empty()
//or
//$('.validation-summary-errors').hide()
})