I have an ASP.NET MVC form laid out something like this:
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "ccform" }))
{
@Html.ValidationSummary(true, "Please correct the errors and try again.")
<fieldset>
...
</fieldset>
}
I have some special processing for this form something like this:
$(function () {
$('#ccform').submit(function (e) {
e.preventDefault();
if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate();
}
if (Page_IsValid) {
...
}
});
});
But I'm finding that Page_ClientValidate is always undefined.
Searching the web, I see that this can be the case when the validation components are not available. But it seems that I everything that's needed for that.
Can anyone offer some tips?
EDIT
As indicated by Nathan, I was off-track. In my Google search, I ended up looking at WebForm validations. It turns out the answer is amazingly simple in MVC.
if ($('#ccform').valid()) {
}
Nice.
Page_ClientValidate()
is part of ASP.NET Webforms validation, and it is not used with ASP.NET MVC. You will have to use something like jQuery Validation for your ASP.NET MVC input validation.