Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4576670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:14:19+00:00 2026-05-21T20:14:19+00:00

I have a model class that has an AreDuesPaid property that I want only

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:14:20+00:00Added an answer on May 21, 2026 at 8:14 pm

    Here is the solution I ended up going with:

    1. Use view models instead of models. So, in this case, I created a class called ViewModels.ClubMember.EditorModel.
    2. For any properties that are admin-only, place them in a separate class. In this case, ViewModels.ClubMember.AdminEditorModel
    3. Make AdminEditorModel a property on EditorModel.
    4. When requesting an EditorModel, the service that gets the model checks the credentials of the logged-in user. If the user is an admin, the AdminEditorModel property is populated, otherwise, it gets set to null.
    5. In the view, use EditorForModel() to render the EditorModel, then, if the AdminEditorModel is not null, use EditorFor(model => model.AdminEditorModel) to scaffold the remaining properties. (Note: AdminEditorModel will not be automatically scaffolded when doing EditorForModel() because the default object template specifically ignores complex properties.)

    This took some work to implement, but so far, I’m finding it to be a fairly clean solution. It seems to work well with validation, too.

    Update

    Based on some of the comment on ebb’s answer (especially Danny’s), I decided to sure things up a little more by using completely separate pages for admins vs. regular users. Each page gets it’s own view model (EditorModel and AdminEditorModel). This took even more work then my initial solution (I had to add new actions to my controller and add mappings between view models and models, but the end result is yet another level cleaner and definitely more secure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cart model class that has a List property like so: public
I have a ViewController class that has a property that is the model which
In my business model I have Entity class (IPoint interface ) that has a
I have a class that contains data from some model. This class has metadata
I have an ActiveRecord model class Foo that has_many Bar . I want to
I have a model class that has, among other things: class Group < ActiveRecord::Base
I have a model that has an array of Strings called tags, public class
I have a WorderOrder class that has predefined work order types: class WorkOrder( models.Model
I've converted a string property in my model to a class that has implicit
I have a model that has an image attached to it that I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.