MVC Edit problem

Aug 30 2018 12:02 AM
Hi ,
 
I have created a form with MVC with the field :
 
[Id]
,[FirstName]
,[Username]
,[Email]
,[Password]
,[Salt]
,[Designation]
 
Now i want to edit this data in the Edit view without including
 
,[Password]
,[Salt]
 
so i remove those two field form the edit view . but after edit when i am trying to update those two field, its becoming NULL value ([Password],[Salt]) .
 
Now here is the problem ... I dont want to edit those field . i want password and salt value would be the same value which was inserted in the time of Creation.
 
in the edit field only
 
[Id]
,[FirstName]
,[Username]
,[Email]
,[Designation]
 
i want.
 
here is my code for edit :
  1. [HttpPost]  
  2. [ValidateAntiForgeryToken]  
  3. public ActionResult Edit([Bind(Exclude = "Password,Salt")] User user)  
  4. {  
  5. if (ModelState.IsValid)  
  6. {  
  7. db.Entry(user).State = EntityState.Modified;  
  8. db.SaveChanges();  
  9. return RedirectToAction("Index");  
  10. }  
  11. return View(user);  
  12. }  
i also written this code....
  1. [HttpPost]  
  2. [ValidateAntiForgeryToken]  
  3. public ActionResult Edit(int? Id, User user)  
  4. {  
  5. if (ModelState.IsValid)  
  6. {  
  7. User Objuser = db.User.Single(x => x.Id == id);  
  8. user.Password = Objuser.Password;  
  9. user.Salt = Objuser.Salt;  
  10. db.Entry(user).State = EntityState.Modified;  
  11. db.SaveChanges();  
  12. return RedirectToAction("Index");  
  13. }  
  14. return View(user);  
  15. }  
both the code is given error.
 
can anyone help me out plz ?

Answers (1)