我创建了一个简单的更改密码屏幕,为此,我创建了一个局部视图,每当“更改密码”时,我都会创建一个部分视图。链接将被点击,部分视图将加载为jquery模式对话框。一切都在起作用,除了两件事。
任何人的帮助将不胜感激。以下是我的代码。
------部分视图-----
<div id="cPassword" style="display:none;">
@using (Html.BeginForm("", "", FormMethod.Post, new { id = "changePwd" }))
{ <center>
<div id="confirmMessage" class="hidden"></div>
</center>
<br />
<label for="OldPasswordL">Old Password:</label>
<div>@Html.Password("OldPassword")</div>
<div>
<label id="OldPasswordV" class="hidden">Old password is required.</label>
</div>
<label for="NewPasswordL">New Password:</label>
<div>@Html.Password("NewPassword")</div>
<div>
<label id="NewPasswordV" class="hidden">New password is required.</label>
</div>
<label for="ConfirmNewPasswordL">Confirm New Password:</label>
<div>@Html.Password("ConfirmNewPassword")</div>
<div>
<label id="ConfirmNewPasswordV" class="hidden">Confirm password is required.</label>
</div>
<br />
<div>
<input type="button" value="Submit" id="btnSubmit" /> <input type="button" value="Close" id="btnClose" />
</div>
}
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#cPassword").dialog({
create: function (event, ui) {
$("body").css({ overflow: 'hidden' })
},
modal: true,
title: ": : Change Password : :"
});
$('#btnClose').click(function () {
$('#cPassword').dialog('close');
});
$('#ConfirmMessage').hide();
$('#OldPassword').keyup(function () {
if ($('#OldPassword').val().length == 0) {
$('#OldPasswordV').addClass('visible');
}
else {
$('#OldPasswordV').removeClass('visible');
$('#OldPasswordV').addClass('hidden');
}
});
$('#NewPassword').keyup(function () {
if ($('#NewPassword').val().length == 0) {
$('#NewPasswordV').addClass('visible');
}
else {
$('#NewPasswordV').removeClass('visible');
$('#NewPasswordV').addClass('hidden');
}
});
$('#ConfirmNewPassword').keyup(function () {
if ($('#ConfirmNewPassword').val().length == 0) {
$('#ConfirmNewPasswordV').addClass('visible');
}
else {
$('#ConfirmNewPasswordV').removeClass('visible');
$('#ConfirmNewPasswordV').addClass('hidden');
}
});
$('#ConfirmNewPassword').blur(function () {
comparePassword();
});
$('#btnSubmit').click(function () {
if ($('#OldPassword').val().length == 0) {
$('#OldPasswordV').addClass('visible');
return false;
}
if ($('#NewPassword').val().length == 0) {
$('#NewPasswordV').addClass('visible');
return false;
}
if ($('#ConfirmNewPassword').val().length == 0) {
$('#ConfirmNewPasswordV').addClass('visible');
return false;
}
if (comparePassword() == true) {
$.post("User/changePassword", $('#changePwd').serialize(), function (data) {
$("#confirmMessage").show().delay(5000).queue(function (n) {
$('#cPassword').dialog('close');
});
});
}
});
function comparePassword() {
if ($('#ConfirmNewPassword').val() != $('#NewPassword').val()) {
$('#confirmMessage').addClass('visible');
$('#confirmMessage').text('Passwords are not same.');
return false;
}
else {
$('#confirmMessage').removeClass('visible');
$('#confirmMessage').addClass('hidden');
$('#confirmMessage').text('');
return true;
}
}
});
</script>
------ ------控制器
public ActionResult changePassword()
{
return PartialView("_changePassword");
}
答案 0 :(得分:0)
以下是打开“更改密码”对话框的代码
@Ajax.ActionLink("Change Password","changePassword", "User",new AjaxOptions {UpdateTargetId = "partialDiv"})
<div id="partialDiv"></div>