public ActionResult Create(UserViewModel model) { if (ModelState.IsValid) { // Create new member var result = Repository.CreateUser(new User() { UserId = Guid.NewGuid(), Email = model.Email, Name = model.Name, Username = model.Username, Password = model.Password }); if (result) { // Ajax requests to Create will return a Json result if (Request.IsAjaxRequest()) { return Json(GetMemberList()); } return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Error creating user"); if (Request.IsAjaxRequest()) { return Json(new { Error = "Failed to add user to the repository" }); } return RedirectToAction("Create"); } } if (Request.IsAjaxRequest()) { return Json(new { Error = "Input error with model" }); } return RedirectToAction("Create"); }
public ActionResult Create() { var model = new UserViewModel(); return View(model); }