-1

There is some ViewModel:

class MyViewModel
{
    [Required(ErrorMessage = "Field {0} is required")]
    public string Email { get; set; }
}

I use jquery validation for front-end:

<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.16.0/jquery.validate.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validation.unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js">
</script>

The fragment of Razor markup:

<form asp-controller="Account" asp-action="Register" role="form">
      <div class="form-group">
           <div asp-validation-summary="All" class="text-danger"></div>
       </div>
        <div class="form-group">
             <label asp-for="Email"></label>
             <input asp-for="Email" class="form-control" aria-describedby="email" />
             <span asp-validation-for="Email" class="text-danger"></span>
       </div>
</form>

The issue is validation is triggered immediately when user get the html page. So one sees error for email field when she inputs nothing yet (Field Email is required). How can I prevent this behavior (triggered on submit)?

Sparky
  • 98,165
  • 25
  • 199
  • 285
Ilya Loskutov
  • 1,967
  • 2
  • 20
  • 34
  • That's not the normal behavior and it's not anything that can be explained by the code you've posted. Something else must be triggering it. – Sparky Apr 14 '17 at 16:55

1 Answers1

0

There is action:

public IActionResult SomeAction(MyViewModel model = null)
{
   return View(model);
}

i.e. controller pass to action null model (value by default). It is the reason of that behavior of jquery validation

Ilya Loskutov
  • 1,967
  • 2
  • 20
  • 34