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 7739043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:25:18+00:00 2026-06-01T08:25:18+00:00

How can I access metadata (dataannotations attributes) in my asp.net mvc model class from

  • 0

How can I access metadata (dataannotations attributes) in my asp.net mvc model class from a T4 scaffolding template?

I’m trying to read the ScaffoldColumn attribute in the T4 template so it should know if must render some columns in the index view

Thanks

  • 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-06-01T08:25:20+00:00Added an answer on June 1, 2026 at 8:25 am

    From within a T4 template you can access attributes from your model using reflection. If you take a look at the existing ASP.NET MVC 3 T4 templates you will see an example:

    C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML\Details.tt
    

    The basic code involved is shown below:

    foreach (PropertyInfo prop in mvcHost.ViewDataType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
          if (Scaffold(prop)) {
              // ...
          }
    }
    
    bool Scaffold(PropertyInfo property) {
        foreach (object attribute in property.GetCustomAttributes(true)) {
            var scaffoldColumn = attribute as ScaffoldColumnAttribute;
            if (scaffoldColumn != null && !scaffoldColumn.Scaffold) {
                return false;
            }
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can access the database either from a .NET program (using ODBC) or through
I'm trying to access the KPI metadata via ADOMD.NET (using MDSCHEMA rowsets) with SQL
I read on a post that you can use ASP.Net authorization in the web
How can I access/remove PNG metadata? I'm looking for a Mac application or a
How can hibernate can access a private field/method of a java class , for
I know you can access the Contact Store from the SDk, but is it
I know that I can get access to column properties via: select * from
How can I access the view parameters from a viewscoped bean? I have a
My group builds internally hosted ASP.NET MVC websites with forms-authentication. I'd like to host
I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in

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.