Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a registration form, whose Register.cshtml file looks like below :


<div class="form-group">
       @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
       <div class="col-md-10">
           @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
           @Html.ValidationMessageFor(m => m.Email, "Please enter email address.", new { @class = "text-danger" })

       </div>
   </div>
   <div class="form-group">
       @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
       <div class="col-md-10">
           @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
           @Html.ValidationMessageFor(m => m.Password, "Please enter password.", new { @class = "text-danger" })
       </div>
   </div>


and the Register action methods as below :

[AllowAnonymous]
       [HttpGet]
       public ActionResult Register()
       {
           return View();
       }

       //
       // POST: /Account/Register
       [HttpPost]
       [AllowAnonymous]
       [ValidateAntiForgeryToken]
       public async Task<ActionResult> Register(RegisterViewModel model)
       {
           if (ModelState.IsValid)
           {
              //some code inside
           }

           // If we got this far, something failed, redisplay form
           return View(model);
       }


The validation error messages are fired even before i click on the submit button of the form.
Should i be adding any specific code to control that?
Posted
Updated 29-Jul-15 1:32am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900