Page_ClientValidate未定义(ASP.NET MVC) [英] Page_ClientValidate is Undefined (ASP.NET MVC)

查看:75
本文介绍了Page_ClientValidate未定义(ASP.NET MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC表格,如下所示:

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) {
           ...
        }
    });
});

但我发现Page_ClientValidate 总是未定义。

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?

编辑

如Nathan所示,我偏离轨道。在我的谷歌搜索中,我最终看到了WebForm验证。事实证明,在MVC中答案非常简单。

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()) {
}

很好。

推荐答案

Page_ClientValidate()是ASP.NET Webforms验证的一部分,它不与ASP.NET MVC一起使用。对于ASP.NET MVC输入,您必须使用 jQuery Validation 之类的内容验证。

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.

这篇关于Page_ClientValidate未定义(ASP.NET MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆