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 :
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Exclude = "Password,Salt")] User user)
- {
- if (ModelState.IsValid)
- {
- db.Entry(user).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(user);
- }
i also written this code....
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(int? Id, User user)
- {
- if (ModelState.IsValid)
- {
- User Objuser = db.User.Single(x => x.Id == id);
- user.Password = Objuser.Password;
- user.Salt = Objuser.Salt;
- db.Entry(user).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(user);
- }
both the code is given error.
can anyone help me out plz ?