I'm using the @Html.ValidationMessageFor helper method for validation but the messages are displayed only when I declare Html.ValidationSummary.
Is there a way to show the error messages next to the elements instead of a Validation summary?
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { id = "registerName" })
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
<div>@Html.ValidationMessageFor(m => m.Password)</div>
</li>
<li>
@Html.LabelFor(m => m.ConfirmPassword)
@Html.PasswordFor(m => m.ConfirmPassword)
<div>@Html.ValidationMessageFor(m => m.ConfirmPassword)</div>
</li>
<li>
<input type="submit" value="Sign up" />
</li>
</ol>
@*@Html.ValidationSummary()*@
</fieldset>
Thanks!
unobtrusiveandvalidatescripts in your page