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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:00:09+00:00 2026-05-23T11:00:09+00:00

So I created a custom Attribute that I will used to decorate StepViewModels. [AttributeUsage(AttributeTargets.Class,

  • 0

So I created a custom Attribute that I will used to decorate StepViewModels.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class WizardStepAttribute : Attribute
{
    public String Name { get; set; }
    //public virtual int? Order { get; set; }
}

[PropertiesMustMatch("Email","ConfirmEmail")]
[WizardStep(Name="Preparer's Information")]
public class Step0ViewModel : IStepViewModel
{...

In my IStepViewModel.cshtml I want to display the WizardStep property name if it exists.

Here is my own pretend code for what I want to happen…

@Html.Label(ViewModel.ModelMetaData.Properties("WizardStep").Name)

  • 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-23T11:00:10+00:00Added an answer on May 23, 2026 at 11:00 am

    The correct way to do this is to implement a custom model metadata provider to add metadata to the model based on the attribute:

    public class MyModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
    
        protected override ModelMetadata CreateMetadata(IEnumerable<System.Attribute> attributes, System.Type containerType, System.Func<object> modelAccessor, System.Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            var wizardStepAttr = attributes.OfType<WizardStepAttribute >().FirstOrDefault();
            if (wizardStepAttr != null)
            {
                metadata.AdditionalValues.Add("WizardStep", wizardStepAttr);
            }
            return metadata;
        }
    }
    

    … then pull that data from the model metadata:

    @Html.Label(((WizardStepAttribute)ViewModel.ModelMetaData.AdditionalValues["WizardStep"]).Name)
    

    You will have to register this metadata provider in Application_Start like so:

        ModelMetadataProviders.Current = new MyModelMetadataProvider();
    

    (Note that some DI Framework extensions for MVC automatically wire this up if you bind ModelMetadataProvider to MyModelMetadataProvider)

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

Sidebar

Related Questions

I've created a custom UITypeEditor. Can I possibly insert an attribute that also attaches
I want to create a custom attribute that can be used on a property
Is there a way to create a custom attribute that will make EF CodeFirst
I'm trying to create a custom attribute that will work in a sort-of AOP
I created a simple custom attribute on the sales/order entity. Now, for new orders,
I created a custom button component that accepts an array as a property. I
I am trying to create a custom jQuery selector that will put focus() on
I have created a custom validation attribute by subclassing ValidationAttribute. The attribute is applied
I would like to create a custom action filter attribute that adds a value
I'm trying to make a simple link that will toggle my status attribute 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.