public static Dictionary <object, object> GetModelRole <TModel>() where TModel : class
        {
            var modelRoleDic      = new Dictionary <object, object>();
            var propDesCollection = TypeDescriptor.GetProperties(typeof(TModel));

            foreach (PropertyDescriptor propDes in propDesCollection)
            {
                var propName   = propDes.Name;
                var attributes = propDes.Attributes;
                var role       = VueValidatorRulePropertyHelper.GetPropRole(propDes);
                modelRoleDic.Add(propDes.Name.ToLower(), role);
            }
            return(modelRoleDic);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取模型的单个属性验证规则
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="helper"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static string VueValidateRoleFor <TModel, TProperty>(this IHtmlHelper helper, Expression <Func <TModel, TProperty> > expression)
        {
            var role = VueValidatorRulePropertyHelper.GetPropRole(expression);

            return(JsonUtil.Serialize(role));
        }