jQuery的客户端验证只能在某一领域(不工作在必填字段) [英] jquery client side validation only works at certain field (doesnt work at Required field)

查看:84
本文介绍了jQuery的客户端验证只能在某一领域(不工作在必填字段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施MVC3客户端验证。
我得到了我的形式通过jQuery对话框中显示,并通过AJAX提交后
我不知道它是必要的,但我在我的模型创建一个部分类以自定义验证:

I am implementing client side validation in mvc3. I got my form showing via jquery dialog, and submit via ajax post I am not sure is it necessary, but i created a partial class in my Model to customize the validation:

[MetadataType(typeof (FoodMetaData))]
public partial class FOOD
{
    [Bind(Exclude="FoodID")]
    public class FoodMetaData
    {
        [ScaffoldColumn(false)]
        public object FoodID { get; set; }

        [Required(AllowEmptyStrings = false, ErrorMessage = "Please enter a name")]
        public object FoodName { get; set; }

        [Range(1, 200, ErrorMessage = "Please enter a valid amount")]
        public object FoodAmount { get; set; }

        public object StorageDate { get; set; }

        public object ExpiryDate { get; set; }

目前我只得到的金额字段中显示,如果我输入一个字符串或数字超出范围的验证。但是,如果我空名称字段,没有发生。

Currently I only get the validation shown at the amount field if i enter a string or a number out of the range. However, If i empty the Name field, nothing happen.

这是我第一次尝试在客户端验证,并有不知道发生了什么。任何人都可以请给我一些建议?

This is my first try on client side validation and got no idea what is happening. Can anyone please give me some advice??

鸭preciate任何帮助,谢谢...

Appreciate any help, thanks...

推荐答案

我刚刚发现后,我经过这里的例子了jQuery的客户端验证仅1表单提交之后触发:<一href=\"http://weblogs.asp.net/imranbaloch/archive/2011/04/30/eagerly-performing-asp-net-mvc-3-unobtrusive-client-side-validation.aspx\" rel=\"nofollow\">http://weblogs.asp.net/imranbaloch/archive/2011/04/30/eagerly-performing-asp-net-mvc-3-unobtrusive-client-side-validation.aspx

I just found out that jquery client side validation is only triggered after 1st form submission after i gone through the example here: http://weblogs.asp.net/imranbaloch/archive/2011/04/30/eagerly-performing-asp-net-mvc-3-unobtrusive-client-side-validation.aspx

一个伟大的!它有助于通过编辑jquery.validate.unobtrusive(.min)来解决我奇怪的问题这个.js文件:

A great one! It helps to solve my weird problem by editing the jquery.validate.unobtrusive(.min).js file by this:

   options: {  // options structure passed to jQuery Validate's validate() method
                errorClass: "input-validation-error",
                errorElement: "span",
                errorPlacement: $.proxy(onError, form),
                invalidHandler: $.proxy(onErrors, form),
                messages: {},
                rules: {},
                success: $.proxy(onSuccess, form),
                onfocusout: function (element) { $(element).valid(); }
            }

感谢每一个帮助!

Thanks for every help!

这篇关于jQuery的客户端验证只能在某一领域(不工作在必填字段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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