62,046
社区成员
发帖
与我相关
我的任务
分享
function ChangePwd() {
window.showModalDialog('../Account/ChangePassWord', '', 'dialogWidth:650px;dialogHeight:340px;dialogTop:' + new String((screen.height - 420) / 2) + 'px;dialogLeft:' + new String((screen.width - 650) / 2) + 'px;resizable:no;status:no;scroll:no;help:no;unadorned:yes;');
}
@Html.BeginForm("ChangePassWord","Account", FormMethod.Post)
<table width="100%" border="0px" cellspacing="0px" cellpadding="0px">
<tr>
<td width="20%" height="30px" align="right" bgcolor="#f2f2f2" class="left_txt2">
用户名:
</td>
<td width="3%" bgcolor="#f2f2f2">
</td>
<td width="32%" height="30px" bgcolor="#f2f2f2">
@Html.TextBoxFor(m => m.UserName, new { name = "txt_username", size = "20",@readonly="readonly" })
</td>
<td width="45%" height="30px" bgcolor="#f2f2f2" class="left_txt">
准备修改密码的所属帐号
</td>
</tr>
<tr>
<td height="30px" align="right" class="left_txt2">
当前密码:
</td>
<td>
</td>
<td height="30px">
@Html.TextBoxFor(m => m.OldPassword, new { name = "txt_oldpassword", size="20" })
</td>
<td height="30px" class="left_txt">
当前密码 <span style=" font-size:12px; color:Red;">@Html.ValidationMessageFor(m => m.OldPassword)</span>
</td>
</tr>
<tr>
<td height="30px" align="right" bgcolor="#f2f2f2" class="left_txt2">
新密码:
</td>
<td bgcolor="#f2f2f2">
</td>
<td height="30px" bgcolor="#f2f2f2">
@Html.TextBoxFor(m => m.NewPassword, new { name = "txt_password",size="20" })
</td>
<td height="30px" bgcolor="#f2f2f2" class="left_txt">
需要设置的新密码 <span style=" font-size:12px; color:Red;">@Html.ValidationMessageFor(m => m.NewPassword)</span>
</td>
</tr>
<tr>
<td height="30px" align="right" bgcolor="#f2f2f2" class="left_txt2">
重新输入新密码:
</td>
<td bgcolor="#f2f2f2">
</td>
<td height="30px" bgcolor="#f2f2f2">
@Html.TextBoxFor(m => m.ConfirmPassword, new { name = "txt_password2",size="20" })
</td>
<td height="30px" bgcolor="#f2f2f2" class="left_txt">
重新输入新密码 <span style=" font-size:12px; color:Red;">@Html.ValidationMessageFor(m => m.ConfirmPassword)</span>
</td>
</tr>
<tr>
<td height="17px" colspan="4" align="right">
</td>
</tr>
<tr>
<td height="30px" colspan="4" class="left_txt2">
<table width="100%" style="height: 40px;" border="0px" cellpadding="0px" cellspacing="0px">
<tr>
<td colspan="4" align="center">
<input id="btn_save" type="submit" value="" style="width: 85px; height: 28px;
background-image: url(../../images/save.gif); cursor: :pointer; border-width: 0px;" />
<input id="btn_close" type="button" value="" style="width: 85px; height: 28px; background-image: url(../../images/close.gif);
cursor: :pointer; border-width: 0px;" onclick="window.close();" />
</td>
</tr>
</table>
</td>
</tr>
</table>
[HttpPost]
public ActionResult ChangePassWord(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
EFDbContext db = new EFDbContext();
var u = db.User.Where(s => s.UserID == CurrentUserInfo.UserID);
u.FirstOrDefault().Password = model.NewPassword;
db.SaveChanges();
return View(model);//请问这里该怎么写?
}
else
{
return View(model);
}
}
[HttpPost]
public ActionResult ChangePassWord(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
EFDbContext db = new EFDbContext();
var u = db.User.Where(s => s.UserID == CurrentUserInfo.UserID);
u.FirstOrDefault().Password = model.NewPassword;
db.SaveChanges();
TempData["CPW"] = "<script>window.close();</script>";
return View(model);
}
else
{
return View(model);
}
}
@if (TempData["CPW"] != null) {
@TempData["CPW"]
}