Exemplo n.º 1
0
        /// <summary>
        /// 获取所有可显示属性标签
        /// </summary>
        /// <param name="widthLabel">是否显示Label</param>
        /// <returns></returns>
        public List <string> GetViewModelPropertyHtmlTag(bool widthLabel)
        {
            List <string> lists = new List <string>();

            foreach (var item in _attribute.GetHtmlTags(false))
            {
                if (_withValue)
                {
                    if (item is DropDownListHtmlTag)
                    {
                        DropDownListHtmlTag tag = item as DropDownListHtmlTag;
                        if (tag.SourceType == Constant.SourceType.ViewData &&
                            ExtendPropertyValue.ContainsKey(tag.SourceKey))
                        {
                            if (ExtendPropertyValue[tag.SourceKey] is Dictionary <string, string> )
                            {
                                tag.DataSource(ExtendPropertyValue[tag.SourceKey] as Dictionary <string, string>);
                            }
                        }
                    }
                    object val = ClassAction.GetObjPropertyValue(_entity, item.Name);
                    item.SetValue(val);
                }
                lists.Add(item.ToString(widthLabel));
            }
            return(lists);
        }
Exemplo n.º 2
0
        public string GetHtmlModelString <T>()
        {
            DataConfigureAttribute attribute     = DataConfigureAttribute.GetAttribute <T>();
            StringBuilder          ColumnBuilder = new StringBuilder();

            if (attribute != null)
            {
                foreach (var item in attribute.GetHtmlTags(true))
                {
                    ColumnBuilder.Append(GetHtmlModelString(item, item.DataType.Name));
                }
            }
            else
            {
                Type tType = typeof(T);
                System.Reflection.PropertyInfo[] propertys = tType.GetProperties();
                foreach (var item in propertys)
                {
                    string typeName = item.PropertyType.Name;
                    if (item.PropertyType.Name == "Nullable`1")
                    {
                        typeName = item.PropertyType.GetGenericArguments()[0].Name;
                    }
                    ColumnBuilder.AppendFormat("{0}:{{ Name: '{0}',DisplayName:'{0}',Width:150,DataType:'{1}',Format:'',,Hidden:0 }},", item.Name, typeName);
                }
            }
            return(string.Format("{{{0}}}", ColumnBuilder.ToString().Trim(',')));
        }