title: How to avoid certain fields to be updated in model using asp.net mvc 4
body: <p>I am new to asp.net mvc 4 and EF. I am creating User Model which creates/updates user info. The code for model is as follows:</p>
  
  <pre><code>....
  public int UserID { get; set; }
  
  [Required]
  public string UserName { get; set; }
  
  [Required]
  public string Password { get; set; }
  
  [Compare("Password")]   
  public string VerifyPassword { get; set; }
  .....
   SOME OTHER FIELDS COMES HERE
  ......
  </code></pre>
  
  <p>This same model used for create/update activity. This works fine for create user but while updating i don't want user to update his Id, username so I keep it readonly also don't want to show user password/verify password fields so I removed it from view. Now while updating(Edit mode) I am always getting validation error message for password field. So my question is how do I avoid updating these fields and do update for other fields. To solve this problem I try to create viewmodel but it doesn't help me. Also added code for bypassing validation like this in controller:</p>
  
  <pre><code>public ActionResult Edit(User user)
  {
     ModelState.Remove("Password");
     ModelState.Remove("VerifyPassword");
     ModelState.Clear();
     if (ModelState.IsValid)
     {
       db.Entry(user).State = EntityState.Modified;
       db.SaveChanges();
       return RedirectToAction("Index");
     }
  }
  </code></pre>
  
  <p>This give me ModelState.IsValid = true but fails to update. Please give me solution to this problem.</p>
  
  <p>Thanks in advance..</p>