public string GetHtmlModelString <T>() { DataConfigureAttribute attribute = DataConfigureAttribute.GetAttribute <T>(); StringBuilder columnBuilder = new StringBuilder(); if (attribute != null) { attribute.InitDisplayName(); foreach (var item in attribute.GetViewPortDescriptors(true)) { columnBuilder.Append(GetHtmlModelString(item, item.DataType.Name)); } } else { Type tType = typeof(T); PropertyInfo[] propertys = tType.GetProperties(); foreach (var item in propertys) { string typeName = item.PropertyType.IsGenericType ? item.PropertyType.GetGenericArguments()[0].Name : item.PropertyType.Name; columnBuilder.AppendFormat("{0}:{{ Name: '{0}',DisplayName:'{0}',Width:150,DataType:'{1}',DateFormat:'',JsDateFormat:'',ValueDateFormat:'',Hidden:0 }},", item.Name, typeName); } } return(string.Format("{{{0}}}", columnBuilder.ToString().Trim(','))); }
public EasyModelMetaData(ModelMetadataProvider provider, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName) : base(provider, containerType, modelAccessor, modelType, propertyName) { if (containerType != null) { DataConfigureAttribute custAttribute = DataConfigureAttribute.GetAttribute(containerType); if (custAttribute != null) { custAttribute.InitDisplayName(); if (custAttribute.MetaData.ViewPortDescriptors.ContainsKey(propertyName)) { ViewPortDescriptor = custAttribute.MetaData.ViewPortDescriptors[propertyName]; DisplayFormatString = ViewPortDescriptor.ValueFormat; if (!string.IsNullOrEmpty(ViewPortDescriptor.DisplayName)) { DisplayName = ViewPortDescriptor.DisplayName; } else { DisplayName = ViewPortDescriptor.Name; } EditFormatString = ViewPortDescriptor.ValueFormat; IsReadOnly = ViewPortDescriptor.IsReadOnly; IsRequired = ViewPortDescriptor.IsRequired; Order = ViewPortDescriptor.OrderIndex; ShowForDisplay = ViewPortDescriptor.IsShowForDisplay; ShowForEdit = ViewPortDescriptor.IsShowForEdit; TemplateHint = ViewPortDescriptor.TemplateName; HideSurroundingHtml = ViewPortDescriptor.IsHidden; } if (custAttribute.MetaData.PropertyDataConfig.ContainsKey(propertyName)) { PropertyData = custAttribute.MetaData.PropertyDataConfig[propertyName]; } } } }