我正在尝试使用以下控制器方法更新密码。
public ActionResult ChangePassword([Bind(Include = "NewPassword")] Register ChangePassword, FormCollection frm)
{
string Email = Session["email"].ToString();
var existingEmail = db.Registers.FirstOrDefault(c => c.EmailId == Email);
if (existingEmail != null)
{
//Need to update password
}
return View();
}
下面是寄存器模型。
[Table("Register")]
public class Register
{
[Key]
public int Sno { get; set; }
[Required(ErrorMessage = "Name is required.")]
[Display(Name = "Full name")]
public string Fullname { get; set; }
[Display(Name = "Email Id")]
[Required(ErrorMessage = "Email is required.")]
public string EmailId { get; set; }
[Required(ErrorMessage = "Password is required.")]
public string Password { get; set; }
[Required(ErrorMessage = "Mobile is required.")]
public string Mobile { get; set; }
[Required(ErrorMessage = "Address is required.")]
public string Address { get; set; }
public string State { get; set; }
public string City { get; set; }
[Required(ErrorMessage = "Entity is required.")]
public string EntityType { get; set; }
public string Website { get; set; }
public string PinCode { get; set; }
public string accountactivated { get; set; }
public int RoleId { get; set; }
[Display(Name = "New Password")]
[NotMapped]
public string NewPassword { get; set; }
[Display(Name = "Confirm New Password")]
[NotMapped] // Does not effect with your database
[System.Web.Mvc.Compare("NewPassword", ErrorMessage = "Password not match")]
public string ConfirmNewPassword { get; set; }
}
下面是我的更改密码设计
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.NewPassword, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.NewPassword, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.NewPassword)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ConfirmNewPassword, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.PasswordFor(model => model.ConfirmNewPassword, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ConfirmNewPassword)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Change Password" class="btn btn-default" />
</div>
</div>
</div>
}
请帮助解决这种情况并等待您的答复。我是第一次使用asp.net mvc代码开发我的项目,这也是我正在做的第一个项目。我先感谢一下。