public ActionResult EditSidebar() { //Declare Model SidebarVM model; using (DataContext db = new DataContext()) { //Need to get DTO SidebarDTOes dto = db.Sidebar.Find(1); //always going to be one that's why it's hard-coded //Initialize model model = new SidebarVM(dto); //return view with model return(View(model)); } }
public ActionResult EditSidebar(SidebarVM model) { using (DataContext db = new DataContext()) { //Get the DTO SidebarDTOes dto = db.Sidebar.Find(1); //DTO the body dto.Body = model.Body; //Save db.SaveChanges(); //Set tempData TempData["SM"] = "You have successfully edited the Sidebar!"; //Redirect return(RedirectToAction("EditSidebar")); } }
public SidebarVM(SidebarDTOes row) { Id = row.Id; Body = row.Body; }