1.5.4.Anti-forgery Tokens
@Html.AntiForgeryToken()[HttpPost] [ValidateAntiForgeryToken] public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { var viewModel = new CustomerFormViewModel { customer = customer, MembershipTypes = _context.membershipType.ToList() }; return View("CustomerForm", viewModel); } if (customer.Id == 0) { _context.Customers.Add(customer); } else { var customersInDb = _context.Customers.Single(c => c.Id == customer.Id); customersInDb.Name = customer.Name; customersInDb.Birthday = customer.Birthday; customersInDb.membershipTypeId = customer.membershipTypeId; customersInDb.IsSubscribeToNesletter = customer.IsSubscribeToNesletter; } _context.SaveChanges(); return RedirectToAction("Index", "Customers"); }
Last updated