I have a Model as follows:
public class ApplicationUser
{
public Int64 Id { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
And my Controller has Actions to Edit the Model as follows:
public ActionResult MyProfile(int id)
{
var currentUser = _context.ApplicationUsers.Find(applicationuser.Id);
return View(currentUser);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MyProfile([Bind(Exclude="Password")]ApplicationUser applicationuser)
{
if (ModelState.IsValid)
{
_context.Entry(applicationuser).State = EntityState.Modified;
_context.SaveChanges();
return RedirectToAction("Index");
}
return View(applicationuser);
}
Here, POST method is updating the FullName and Email fields properly. But, It's updating NULL value to Password field. How to avoid this?