I have page , where i can Edit User's Email and Password not problem ,but there is problem, when its send Data to Database , it will add new row everytime , when i just trying to edit User's Email, so how can i avoid that to not add new row in database , just send data in same row with out adding new row.
The code i have in my Action:
- public ActionResult UserEdit(string Email)
- {
- return View(new user {Email = Email });
- }
-
- [HttpPost]
- [ValidateAntiForgeryToken]
-
- public ActionResult UserEdit(user User)
- {
- var db = new DataContext();
- var u = db.PX.Where(t => t.Email_ID == User.Email).FirstOrDefault();
- if (u == null)
- db.PX.Add(new A_S_PX { Email_ID = User.Email, PS = User.Password });
- else {
- u.PS = User.Password;
- u.Email_ID = User.Email;
-
- }
- db.SaveChanges();
- return View(new user { Email = User.Email });
-
-
- }