ASP.NET MVC和部分客户端验证 [英] ASP.NET MVC and partial client side validation

查看:135
本文介绍了ASP.NET MVC和部分客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想在不同的步骤拆分巨大的形式,但我需要验证在当前步骤的领域转到下一步骤之前。

I have huge form that I'd like to split in different steps, but I need to validate the fields in the current step before go to the next step.

例如:我表单有40场,他们在4个步骤分为(各10场)。在HTML中40是在同一个页面,但使用​​jQuery我只显示前10和下一个按钮,第四页包含提交按钮。我需要一种方法来调用这些十个字段的验证转到下一步骤之前。

E.g.: My form has 40 fields, and they are divided in 4 steps (10 fields each). In the HTML the 40 are in the same page, but with jQuery I only show the first 10 and a next button, the fourth page contains the "Submit" button. I need a way to invoke the validation of those ten fields before go to the next step.

有没有办法做到这一点?

Is there any way to accomplish this?

问候。

推荐答案

如果您正在使用按钮来每一步之间移动,你可以修改你的网页,我们每一步一个独立的形式。然后,可能会限制验证到其提交按钮的父的形式,并且使用验证的台阶,以确定是否启用/显示的下一个步骤的形式。下面是一些例子code:

If you are using buttons to move between each step, you can revise your page to have a separate form for each step. You then may limit validation to the form which is the parent of the submit button, and use the validation for the "step" to determine whether to enable/show the form for the next step. Here is some example code:

$(".stepButton").live("click", function() {
    if (isValid(this)) {
        // code to proceed to next step
    }
});

function isValid(el) {
    var $thisform = $(el).parent().parent();
    $thisform.validate();
    return $thisform.valid();
}

这篇关于ASP.NET MVC和部分客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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