Page_ClientValidate is Undefined (ASP.NET MVC)

Go To StackoverFlow.com

2

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.

2012-04-05 18:06
by Jonathan Wood


2

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.

2012-04-05 18:20
by Nathan Taylor
Hmm... perhaps you are right there. However, I'm not sure why I'd use that jQuery Validation. ASP.MVC already includes client-side validation. I just want to hook into that - Jonathan Wood 2012-04-05 18:56
jQuery Validation is considered the de facto solution for validation with ASP.NET MVC - Nathan Taylor 2012-04-05 20:43
Ads