Example #1
0
        /// <summary>
        /// 解析 <see cref="ValidationAttribute"/> 对象。
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="validation">要解析的 <see cref="ValidationAttribute"/> 对象。</param>
        /// <param name="validTypes">如果 <paramref name="validation"/>  能与 EasyUI 的客户端验证所对应,则添加到 validType 属性中。</param>
        protected virtual void ParseValidation(ValidateBoxSettings settings, ValidationAttribute validation, List <string> validTypes)
        {
            //必填验证特性
            if (validation is RequiredAttribute required)
            {
                settings.Required = true;
                return;
            }

            //长度验证特性
            if (validation is StringLengthAttribute stringLength)
            {
                validTypes.Add(string.Format("length[{0},{1}]", stringLength.MinimumLength, stringLength.MaximumLength));
                return;
            }

            //电话验证特性
            if (validation is TelphoneAttribute telphone)
            {
                validTypes.Add("phone");
                return;
            }

            //手机验证特性
            if (validation is MobileAttribute mobile)
            {
                validTypes.Add("mobile");
                return;
            }

            //手机或电话验证特性
            if (validation is TelphoneOrMobileAttribute telOrMobile)
            {
                validTypes.Add("phoneOrMobile");
                return;
            }

            //邮箱验证特性
            if (validation is EmailAttribute email)
            {
                validTypes.Add("email");
                return;
            }
        }
Example #2
0
        /// <summary>
        /// 解析 <see cref="ValidationAttribute"/> 对象。
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="validation">要解析的 <see cref="ValidationAttribute"/> 对象。</param>
        /// <param name="validTypes">如果 <paramref name="validation"/>  能与 EasyUI 的客户端验证所对应,则添加到 validType 属性中。</param>
        private void ParseValidation(ValidateBoxSettings settings, ValidationAttribute validation, List <string> validTypes)
        {
            //必填验证特性
            if (validation is RequiredAttribute required)
            {
                settings.Required = true;
                return;
            }

            //长度验证特性
            if (validation is StringLengthAttribute stringLength)
            {
                validTypes.Add(string.Format("length[{0},{1}]", stringLength.MinimumLength, stringLength.MaximumLength));
                return;
            }

            //电话验证特性
            if (validation is TelphoneAttribute telphone)
            {
                validTypes.Add("phone");
                return;
            }

            //手机验证特性
            if (validation is MobileAttribute mobile)
            {
                validTypes.Add("mobile");
                return;
            }

            //手机或电话验证特性
            if (validation is TelphoneOrMobileAttribute telOrMobile)
            {
                validTypes.Add("phoneOrMobile");
                return;
            }

            //邮箱验证特性
            if (validation is EmailAttribute email)
            {
                validTypes.Add("email");
                return;
            }

            if (validation is AsciiCodingAttribute ascii)
            {
                validTypes.Add("ascii");
                return;
            }

            if (validation is UserNameAttribute un)
            {
                validTypes.Add("username");
                return;
            }

            if (validation is UnicodeCodingAttribute chinese)
            {
                validTypes.Add("chinese");
            }
        }
 /// <summary>
 /// 为 <see cref="HtmlHelper"/> 对象扩展 validatebox 元素。
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="exp">属性名或使用 txt 作为前缀的 ID 名称。</param>
 /// <param name="settings">参数选项。</param>
 /// <returns></returns>
 public static HtmlHelper ValidatePasswordBox(this System.Web.Mvc.HtmlHelper htmlHelper, string exp, ValidateBoxSettings settings = null)
 {
     return(new HtmlHelper().ValidatePasswordBox(exp, settings));
 }
 /// <summary>
 /// 为 <see cref="HtmlHelper"/> 对象扩展 validatebox 元素。
 /// </summary>
 /// <typeparam name="TModel">数据模型类型。</typeparam>
 /// <typeparam name="TProperty">绑定的属性的类型。</typeparam>
 /// <param name="htmlHelper"></param>
 /// <param name="expression">指定绑定属性的表达式。</param>
 /// <param name="settings">参数选项。</param>
 /// <returns></returns>
 public static HtmlHelper <TModel> ValidateMultiBox <TModel, TProperty>(this System.Web.Mvc.HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, ValidateBoxSettings settings = null)
 {
     return(new HtmlHelper <TModel>().ValidateMultiBox(expression, settings));
 }
Example #5
0
        /// <summary>
        /// 解析 <see cref="ValidationAttribute"/> 对象。
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="validation">要解析的 <see cref="ValidationAttribute"/> 对象。</param>
        /// <param name="validTypes">如果 <paramref name="validation"/>  能与 EasyUI 的客户端验证所对应,则添加到 validType 属性中。</param>
        private void ParseValidation(ValidateBoxSettings settings, ValidationAttribute validation, List <string> validTypes)
        {
            //必填验证特性
            var required = validation as RequiredAttribute;

            if (required != null)
            {
                settings.Required = true;
                return;
            }

            //长度验证特性
            var stringLength = validation as StringLengthAttribute;

            if (stringLength != null)
            {
                validTypes.Add(string.Format("length[{0},{1}]", stringLength.MinimumLength, stringLength.MaximumLength));
                return;
            }

            //电话验证特性
            var telphone = validation as TelphoneAttribute;

            if (telphone != null)
            {
                validTypes.Add("phone");
                return;
            }

            //手机验证特性
            var mobile = validation as MobileAttribute;

            if (mobile != null)
            {
                validTypes.Add("mobile");
                return;
            }

            //手机或电话验证特性
            var telOrMobile = validation as TelphoneOrMobileAttribute;

            if (telOrMobile != null)
            {
                validTypes.Add("phoneOrMobile");
                return;
            }

            //邮箱验证特性
            var email = validation as EmailAttribute;

            if (email != null)
            {
                validTypes.Add("email");
                return;
            }

            var ascii = validation as AsciiCodingAttribute;

            if (ascii != null)
            {
                validTypes.Add("ascii");
                return;
            }

            var un = validation as UserNameAttribute;

            if (un != null)
            {
                validTypes.Add("username");
                return;
            }

            var chinese = validation as UnicodeCodingAttribute;

            if (chinese != null)
            {
                validTypes.Add("chinese");
            }
        }