asp.net - When building a datagrid helper, how do you access the new data annotation attributes using Reflection? -


After

I have eagerly added the name of the system.ComponentModel.DataAnnotations to my model.

I am involved in Ve:

  [required] [DisplayName ("first name")] public string first_name {get; Set;}  

I really like these properties, because they save me from writing custom T4 and / or modifying it in a heavily modified format. In this way, I can rebuild a belief that it will add display names to my name. Etc.

The problem comes when I started constructing one-driven Data Grid Assistant in ASP.Net MVC 2.

In this assistant, Stephen uses reflection on column headings.

  value = typeof (t) .GetProperty (columnName) .GetValue (item, tap) ?? String.Empty; Well, the problem is that I do not want to retrieve the name of the property. I want to retrieve the value for the DisplayName feature.  

My first attempt at this was to look inside the properties properties of property properties. Unfortunately, no data annotation is visible as a feature.

Is there a way to get data annotation using Reflection?

Thanks

/ p>

  var properties = ( DisplayNameAttribute []) Typef (T) .GetProperty (columnName) .GetCustomAttributes (TypePoint (DisplayNameAttribute), True); // TODO: Check for nonsense and array size displayName = attributes [0]. DisplayName;  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -