views:

17

answers:

1

Just wondering why I get compile time error : "Attribute 'DisplayColumn' is not valid on this declaration type. It is only valid on 'class' declarations."

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MyApplication.Models.DataAnnotations
{

    [MetadataType(typeof(AppUser_DataAnnotations))]
    public partial class AppUser
    {

    }

    public class AppUser_DataAnnotations
    {
        [DisplayColumn("Name")]
        public string FirstName { get; set; }
    }
}

I'm using above to override mvccontrib rendered grid column headers. Any idea why I get compile time error? Any help would be greatly appreciated.

Thanks :)

+1  A: 

The reason you are getting a compile-time error is because the [DisplayColumn] attribute can only be applied at the class level and not at a property of the class. You are probably confusing this attribute with [DisplayName].

Darin Dimitrov
Ohhh my bad. Good catch thanks ! But I do not find [DisplayName] anywhere. Am I missing some namespace? Thanks.
Gurdeep
Found it... using System.ComponentModel; is what was missing. Still, I don't get the header overriden.
Gurdeep