public IActionResult GridViewPartialUpdate(UserIdentity.Models.AppUser item) { var db = HttpContext.RequestServices.GetService(typeof(UserIdentity.Models.AppIdentityDbContext)) as UserIdentity.Models.AppIdentityDbContext; try { if (ModelState.IsValid) { db.Users.Update(item); db.SaveChanges(); } } catch (Exception e) { ViewData["error"] = e.Message; } return(PartialView("~/Views/Admin/GridViewPartial.cshtml", db.Users)); }
public IActionResult GridViewPartialAddNew(UserIdentity.Models.AppUser item) { var db = HttpContext.RequestServices.GetService(typeof(UserIdentity.Models.AppIdentityDbContext)) as UserIdentity.Models.AppIdentityDbContext; try { if (ModelState.IsValid) { item.Id = db.Users.Max(p => p.Id) + 1; // Remove this line if your Primary Key is automatically incremented at your database/model level db.Users.Add(item); db.SaveChanges(); } } catch (Exception e) { ViewData["error"] = e.Message; } return(PartialView("~/Views/Admin/GridViewPartial.cshtml", db.Users)); }