I'm using MVC3 with Razor.
I've included the following in my _Layout.cshtml:
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
My form looks like:
@{
ViewBag.Title = "Register";
Html.EnableClientValidation();
}
@using (Html.BeginForm("Register"))
{
<fieldset>
<p>
@Html.LabelFor(o => o.Email)
@Html.TextBoxFor(o => o.Email)
@Html.ValidationMessageFor(o => o.Email)
</p>
...
</fieldset>
}
My ViewModel has DataAnnotations (and implements IValidatableObject), and it validates during controller action. However I cannot seem to be able to use JS validation on the clientside without posting the form.
What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…