リンクに
<a href="#myModal" id="modalLink" role="button" data-toggle="modal" data-target="#myModal">Change Password</a>
を与え、
<div id="myModal" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center">
<div class="modal-content" style="height:400px;width:350px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Change Password</h4>
</div>
<div class="modal-body">
@Html.Partial("_ChangePassword", Model.ObjChangePasswordModel)
</div>
</div>
</div>
</div>
</div>
が近いポップアップで
$('#myModal').on('hidden.bs.modal', function (e) {
$(this)
.find("input,textarea,select,span")
.val('')
.end()
.find("input[type=checkbox], input[type=radio]")
.prop("checked", "")
.end();
$('.field-validation-error').each(function() {
$(this).html("");
})
})
をすべてクリア検証メッセージとコントロールデータのためのいくつかのスクリプトを記述し、いくつかのdivを定義します部分図のコード
@model CAT_MVC.Models.ChangePasswordModel
Scripts.Render( "〜/バンドル/ jqueryval")検証サーバ側と表示エラーメッセージの
<div style="height:400px;width:350px;">
@using (Html.BeginForm("ChangePassword", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="row-fluid">
<label for="CurrentPassword" class="form-control-label">Enter Current Password:</label>
@Html.PasswordFor(m => m.CurrentPassword, new { @class = "form-control", @id = "txtCurrentPassword", style = "width: 300px;padding-bottom:1px;" })
@Html.ValidationMessageFor(m => m.CurrentPassword, "", new { @class = "message" })
</div>
<div class="row-fluid">
<label for="NewPassword" class="form-control-label">Enter New Password:</label>
@Html.PasswordFor(m => m.NewPassword, new { @class = "form-control", style = "width: 300px;" })
@Html.ValidationMessageFor(m => m.NewPassword, "", new { @class = "message" })
</div>
<div class="row-fluid">@* *@
<label for="ConfirmPassword" class="form-control-label">Confirm Password:</label>
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control", style = "width: 300px;" })
@Html.ValidationMessageFor(m => m.ConfirmPassword, "", new { @class = "message" })
@Html.ValidationSummary(true, "", new { @class = "message" })
</div>
<div style="height:30px;vertical-align:top;">
<div class="message lblmsg field-validation-error"></div>
</div>
<div class="row-fluid">
<div class="col-md-8 col-md-offset-3">
<button type="button" id="btnCancel" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" id="btnSave" class="btn btn-sm btn-primary">Change Password</button>
</div>
</div>
}
書き込みスクリプト@
とエラーが、その後呼び出していない場合は、サーバー側が
を提出
<script type="text/javascript">
$(function() {
$('#btnSave').click(function (e) {
e.preventDefault();
var element = this;
$.ajax({
type: "POST",
url: '@Url.Action("VerifyOldPassword", "Account")',
data: {
CurrentPassword: $('#txtCurrentPassword').val(),
},
dataType: 'json',
success: function (response) {
if (response != null && response.success) {
$(element).closest("form").submit();
// alert("Password changed successfully.");
} else {
$('.lblmsg').html(response.responseText);
}
},
error: function (response) {
alert("error!"); //
}
});
});
$('#btnCancel').click(function() {
$('#modal-container').modal('hide');
});
});
私のソリューションをデバッグして、コードが正常に受信されましたg内のIFブロック内にメッセージが表示されていません。また、部分ビューを使用しない場合でもこのメソッドは正常に動作します。 –
変数内に値を格納し、コード内で使用しようとします。 – NamiraJV
変数を宣言し、それに応じて上記のコードを更新しました。 (私はそれを修正します)。しかし、私はポップアップ内の保存ボタンを押すと、警告パネルが消えてしまいます。 –