如何使用用户ID?管理页面将用户密码更改为null
?
我在登录模型中有这个代码:
public string userId { get; set; }
public string userPassword { get; set; }
public string userName { get; set; }
在重置模型中:
public string userId{ get; set; }
[Compare("userId", ErrorMessage = "not matched")]
public string confirmId{ get; set; }
在控制器中:
public ActionResult reset([Bind(Include = "userId,confirmId")] Login model1, reset model2) {
bool userExist = dbcontext.Login.Any(contact => contact.userId.Equals(model2.userId));
if (contactExists && model2.userId==model2.confirmId) {
dbcontext.Entry(model1).Property(x => x.LoginPassword).IsModified = true;
dbcontext.Entry(model1).Property(x => x.Item1.EmployeeName).IsModified = false;
dbcontext.Entry(model1).State = EntityState.Modified;
dbcontext.SaveChanges();
}
}
在视图中我有这段代码:
@model BSR.Models.reset
@using (Html.BeginForm()) {
textbox for userId
textbox for confirmId
submitt button
}
我尝试将null
分配给userPassword
,但它不接受数据库表中的null
。我允许它为null
,我应该写什么来将userPassowrd
更改为null
并将其余字段保留为原样,不变?
答案 0 :(得分:0)
尝试使用用户商店:(ASP.NET Identity reset password)
UserManager<IdentityUser> userManager =
new UserManager<IdentityUser>(new UserStore<IdentityUser>());
userManager.RemovePassword(userId);
userManager.AddPassword(userId, newPassword);