Beispiel #1
0
        /// <summary>
        /// 获取属性的ValidBox
        /// </summary>
        /// <param name="property">属性</param>
        /// <param name="message">初始化提示消息</param>
        /// <returns></returns>
        private static ValidBox GetPropertyValidBox(PropertyInfo property, string message)
        {
            var validBox = ValidBox.Empty(message);

            // 值类型非空检测
            if (property.PropertyType.IsValueType && Attribute.IsDefined(property, typeof(RequiredAttribute)) == false)
            {
                validBox = ValidBox.Request(null);
            }

            var boxs = Attribute.GetCustomAttributes(property, false)
                       .Where(item => item is IValidRule)
                       .Cast <IValidRule>()
                       .OrderBy(item => item.OrderIndex)
                       .Select(item => item.ToValidBox());

            foreach (var box in boxs)
            {
                validBox = ValidBox.Merge(validBox, box);
            }

            // 数字类型输入检测
            if (property.PropertyType.IsNumberType() == true)
            {
                validBox = ValidBox.Merge(validBox, ValidBox.New("number", null));
            }
            return(validBox);
        }
Beispiel #2
0
 /// <summary>
 /// 生成前端验证规则
 /// </summary>
 /// <param name="html">html助手</param>
 /// <returns></returns>
 public static ValidBox Valid(this HtmlHelper html)
 {
     return(ValidBox.Empty());
 }
Beispiel #3
0
        /// <summary>
        /// 生成前端验证规则
        /// </summary>
        /// <param name="html">html助手</param>
        /// <param name="field">绑定的ModelState字段名</param>
        /// <returns></returns>
        public static ValidBox Valid(this HtmlHelper html, string field)
        {
            var message = html.ViewData.ModelState.GetErrorMessage(field);

            return(ValidBox.Empty(message));
        }
 /// <summary>
 /// 生成控件的前面验证规则
 /// </summary>
 /// <param name="ctrl">控件</param>
 /// <returns></returns>
 public static ValidBox Valid(this DropDownList ctrl)
 {
     return(ValidBox.Empty(ctrl));
 }
 /// <summary>
 /// 生成控件的前面验证规则
 /// </summary>
 /// <param name="ctrl">控件</param>
 /// <returns></returns>
 public static ValidBox Valid(this TextBox ctrl)
 {
     return(ValidBox.Empty(ctrl));
 }
 /// <summary>
 /// 生成控件的前面验证规则
 /// </summary>
 /// <param name="ctrl">控件</param>
 /// <returns></returns>
 public static ValidBox Valid(this HtmlTextArea ctrl)
 {
     return(ValidBox.Empty(ctrl));
 }
 /// <summary>
 /// 生成控件的前面验证规则
 /// </summary>
 /// <param name="ctrl">控件</param>
 /// <returns></returns>
 public static ValidBox Valid(this HtmlSelect ctrl)
 {
     return(ValidBox.Empty(ctrl));
 }
 /// <summary>
 /// 生成控件的前面验证规则
 /// </summary>
 /// <param name="ctrl">控件</param>
 /// <returns></returns>
 public static ValidBox Valid(this HtmlInputControl ctrl)
 {
     return(ValidBox.Empty(ctrl));
 }