//[ValidateAntiForgeryToken] public IActionResult Create(ResturantEditModel resturantEdit) { if (ModelState.IsValid) { Resturant newRresturant = new Resturant(); newRresturant.Name = resturantEdit.Name; newRresturant.CusineType = resturantEdit.CusineType; newRresturant.Address = resturantEdit.Address; var a = _resturant.Add(newRresturant); //return View("Details", a); ////when user decides to refresh the returned view, //the req. rendered will execute a http post req again to the application //causing redundant data to be saved again. //inorder to solve the above mentioned //issue we'll return a redirect action insted of a view. return(RedirectToAction(nameof(Details), new { a.Id, status = "success" })); } else { return(View()); } }
public IActionResult OnPost() { if (!ModelState.IsValid) { Cuisines = htmlHelper.GetEnumSelectList <CuisineType>(); return(Page()); } if (Resturant.Id > 0) { resturant.Update(Resturant); TempData["Message"] = "New Resturant has been edited"; } else { resturant.Add(Resturant); TempData["Message"] = "New Resturant has been Added"; } return(RedirectToPage("./Details", new { Id = Resturant.Id })); }