ServerSide Validation through validation object

This commit is contained in:
2019-01-23 21:43:27 +01:00
parent ecadd21228
commit 3e501b29d0
7 changed files with 58 additions and 7 deletions

View File

@ -43,7 +43,17 @@ namespace Vidly.Controllers
[HttpPost]
public ActionResult Save(Customer customer)
{
if(customer.Id==0)
if (!ModelState.IsValid)
{
var viewModel = new CustomerFormViewModel
{
Customer = customer,
MembershipTypes = _context.MembershipTypes.ToList()
};
return View("CustomerForm",viewModel);
}
if (customer.Id==0)
_context.Customers.Add(customer);
else
{