I have a model class that has an AreDuesPaid
property that I want only administrators to be able to see and edit.
The class looks something like this:
public class ClubMember
{
[ScaffoldColumn(false)]
public int Id { get; set; }
[Display(Name = "First Name")]
[Required(ErrorMessage = "First name is required")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
[Required(ErrorMessage = "Last name is required")]
public string LastName { get; set; }
[Display(Name = "Email Address")]
[DataType(DataType.EmailAddress)]
public string EmailAddress { get; set; }
[DataType(DataType.PhoneNumber)]
[Display(Name = "Phone Number")]
public string PhoneNumber { get; set; }
[Authorize(Roles="Administrator")] // error: this can only be used for methods
public bool AreDuesPaid{ get; set; }
}
I thought maybe I could use the Authorize
attribute, but the compiler tells me this is only for methods.
So, I'm wondering, how can I limit access to a particular property when using DisplayForModel()
and EditorForModel()
to auto-scaffold views?
Do I need to create entirely separate views and view models or is there an easier way?