I messed around with data annotations. When I click on the link to go to the page, verification messages are displayed, but I would like the verification messages not to appear until the data has been published.
View:
@Html.TextBoxFor(m => m.EmailAddress, new { @placeholder = "Enter Email", @class = "form-control" }) @Html.ValidationSummary(true, "Registration Failed. Check your credentials") @Html.ValidationMessageFor(m => m.EmailAddress, "You must enter a valid Email Address.")
Model:
[Required(ErrorMessage = "Email is required")] [DataType(DataType.EmailAddress)] [EmailAddress] [Display(Name = "Email Address: ")] public string EmailAddress { get; set; }
Controller:
[HttpGet] public ActionResult AddUser() { return View(); } [HttpPost] public ActionResult AddUser(UserCreateViewModel user) { if (ModelState.IsValid) { var success = UserRepository.AddUser(user); if (success) { return View("Success"); } } return View("AddUser"); }
As I said, my problem occurs when the page loads in the AddUser window. When I click the link to view the AddUser page, after it is loaded, verification messages are displayed, but at that moment the data was not published and the model is empty.
c # asp.net-mvc razor data-annotations asp.net-mvc-validation
allencoded
source share