获取类中[DisplayName("")]或[Display("")]属性的方法

public class AttributeHelper
    {
        public static string GetDisplayName(Type modelType, string propertyDisplayName)
        {
            return (TypeDescriptor.GetProperties(modelType)[propertyDisplayName].Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute).DisplayName;
        }

        public static string GetDisplay(Type modelType, string propertyDisplayName)
        {
            return (TypeDescriptor.GetProperties(modelType)[propertyDisplayName].Attributes[typeof(DisplayAttribute)] as DisplayAttribute).Name;
        }
    }

 

你可能感兴趣的:(C#与asp.net,ASP.NET,MVC)