I'm returning a model to my view on the initial load of a page, the model is populated from the DB, I want to validate the model so that when the user receives the page a validation summary show the errors if any.
I have tried using TryValidateModel(model) but this does not work, it does not update the ModelState, the reasion I assume is that it will only validate against what is populated from the ModelBinder
Is there anyway around this? I just want to validate the model first without the user having to post it back...
[Authorize, HttpGet, ActionName("StepOne")] public ActionResult StepOneGET(StepOneModel model) { var individual = _onsideService.Get(User.Identity.Name); model.PersonalInformation = new PersonalInformationModel { FirstName = individual.FirstName, LastName = individual.LastName, DoB = individual.DateOfBirth.ToString("dd/MM/yyyy"), Email = individual.DefaultEmail.EmailAddress, Phone = individual.DefaultPhone.Number, AddressLine1 = location.Address1, AddressLine2 = location.Address2, City = location.City, PostCode = location.PostalCode, Country = location.Country }; // NOTE: Does not update ModelState TryValidateModel(model); // Need to return potential errors to user on page load return View(model); }