使用ASP.NET MVC 3不显眼的验证,我怎么能采取行动时,一种形式是无效的? [英] Using unobtrusive validation in ASP.NET MVC 3, how can I take action when a form is invalid?

查看:201
本文介绍了使用ASP.NET MVC 3不显眼的验证,我怎么能采取行动时,一种形式是无效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它的jQuery UI选项卡的页面,第一个选项卡上的单个必填字段。验证的工作原理,如果用户没有输入一个值出现该字段旁边的验证消息。然而,如果用户是不是第一个标签上,这不是显而易见的字段是无效的。

I have a page with jQuery UI tabs on it, and a single required field on the first tab. Validation works, and the validation message appears next to the field if the user hasn't entered a value. However, if the user is not on the first tab, it isn't obvious that the field is invalid.

在这种情况下,我想显示第一个选项卡,但我不知道如何去注册一个回调为无效情况下,如果存在的话。

In this case, I would like to show the first tab, but I'm not sure how to go about registering a callback for an 'invalid' event, if there is one.

我也有考虑呈现出验证摘要选项卡上方,这将是可见无论用户是在标签的,但我的preference是采取用户到外地。

I have also considered showing a validation summary above the tabs, which would be visible regardless of the tab the user is on, but my preference would be to take the user to the field.

我试过翻翻jquery.validate.unobtrusive.js文件,它似乎延长jquery.validate.js。看着为jquery.validate的文档,我看到有一个可以传递给的 invalidHandler 选项=htt​​p://docs.jquery.com/插件/确认/验证#选项相对=nofollow> validate方法,但我不知道如何使用这个,因为这方法由jquery.validation.unobtrusive调用。

I've tried looking through the jquery.validate.unobtrusive.js file, and it seems to extend jquery.validate.js. Looking at the documentation for jquery.validate, I see there is an invalidHandler option that can be passed to the validate method, but I don't know how to make use of this since that method is called by jquery.validation.unobtrusive.

我感觉有点丢在这里,所以任何帮助将是AP preciated!

I'm feeling a bit lost here, so any help would be appreciated!

修改

我从来没有想出答案,但没有拿出一个解决办法,这是我贴在下面。不过,我希望有一个更好的办法来做到这一点有人回答。

I never figured out the answer, but did come up with a workaround, which I posted below. Still, I hope someone answers with a better way to do this.

推荐答案

我结束了验证和手动提交表单:

I ended up validating and submitting the form manually:

$("#save-button").button().click(function() {
    if (!$("#profile-form").valid()) {
        if ($("#tabs").tabs("option", "selected") > 0) {
            $("#tabs").tabs("option", "selected", 0);
        }
        return false;
    }
    $("#profile-form").submit();
});

这篇关于使用ASP.NET MVC 3不显眼的验证,我怎么能采取行动时,一种形式是无效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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