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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:48:54+00:00 2026-05-29T18:48:54+00:00

I am creating an attribute that I will use to provide additional information about

  • 0

I am creating an attribute that I will use to provide additional information about the unit of measure of a property in an MVC 3 ViewModel. This follows me asking about the best way to accomplish this.

I have created a UnitOfMeasure attribute that passes additional information to the string template via the AdditionalValues metadata. Ideally I would like to create a Editor Template for UnitOfMeasure rather than adding it to the string editor template.

Is there anyway to tell a custom metadata provider to change the selected template? Effectively if it sees the UnitOfMeasure attribute on a property then I would like to also add UiHint(“UnitOfMeasure”) automaticallly behind the scenes. That way I would not have to add code for my UnitOfMeasure helper in the string editor template.

I should note that I don’t want to use UiHint control parameters (unless it is the only option)

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-05-29T18:49:01+00:00Added an answer on May 29, 2026 at 6:49 pm

    You could have your custom attribute derive from UIHint:

    public class UnitOfMeasureAttribute : UIHintAttribute, IMetadataAware
    {
        public UnitOfMeasure(): base("foo")
        {
    
        }
    
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            throw new NotImplementedException();
        }
    }
    

    and then:

    public class MyViewModel
    {
        [UnitOfMeasure]
        public string Foo { get; set; }
    }
    

    or:

    public class MyViewModel
    {
        public string Foo { get; set; }
    }
    

    and in both case in the view:

    @Html.EditorFor(x => x.Foo)
    

    in the first case, obviously the ~/Views/Shared/EditorTemplates/foo.cshtml custom template will be used whereas in the second the default string template.

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

Sidebar

Related Questions

I'm trying to force an inherited class to use a custom attribute. I'm creating
I'm creating function which will read different XML files each time that will contain
When creating a libsvm training file, how do you differentiate between a nominal attribute
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I noticed that some of developers in our team are creating long jQuery selectors
I have a web app that only registered users can use, therefore I should
I was creating a shape to use as a button background. I'm making a
I'm creating some unit tests in Visual Studio, and I want to create a
I've been creating a lot of my own custom attributes in my XHTML documents

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.