public ActionResult AddEditRecord(User user, string cmd) { if (ModelState.IsValid) { if (cmd == "Save") { try { db.Users.Add(user); db.SaveChanges(); return RedirectToAction("Index"); } catch { } } else { try { User us = db.Users.Where(m => m.UserID == user.UserID).FirstOrDefault(); if (us != null) { us.FirstName = user.FirstName; us.LastName = user.LastName; us.Email = user.Email; us.Password = user.Password; us.PhoneWork = user.PhoneWork; us.PhoneMobile = user.PhoneMobile; db.SaveChanges(); } return RedirectToAction("Index"); } catch { } } } if (Request.IsAjaxRequest()) { return PartialView("_UserData", user); } else { return View("UserData", user); } }
// GET: Users/Create public ActionResult CreateUser(string formView) { var dto = new User { FormView = formView }; // return View(); return PartialView("_Create", dto); }