How can I change the user password to null from admin page using user id`?
I have this code in the login model:
public string userId { get; set; }
public string userPassword { get; set; }
public string userName { get; set; }
And in the reset model:
public string userId{ get; set; }
[Compare("userId", ErrorMessage = "not matched")]
public string confirmId{ get; set; }
In the controller:
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();
}
}
In the view I have this code:
@model BSR.Models.reset
@using (Html.BeginForm()) {
textbox for userId
textbox for confirmId
submitt button
}
I tried to assign null to userPassword but it didn't accept null in the database table. I allowed it to be null, what should I write to change the userPassowrd to null and leave the rest fields in the row as they are, unchanged?