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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:51:52+00:00 2026-05-21T02:51:52+00:00

I have the follwing question about MVC 2 with C#. Here is my Model:

  • 0

I have the follwing question about MVC 2 with C#.

Here is my Model:

public class Pmjob
{
   [Tooltext="Hier soll der Name eingegeben werden"]
   [DisplayName("Type")]
   public int Name { get; set; }
}

Now I want to reach the Tooltext item in my view, e. g.:

@Html.ToolTextFor(Model => Model.Pmjob.Name)

or in the BL:

if ( Model.Pmjob.Name.Tooltext == "") {
}

Is this possible?

  • 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-21T02:51:52+00:00Added an answer on May 21, 2026 at 2:51 am

    Create an abstract class MetaDataAttribute :

    public abstract class MetadataAttribute : Attribute
    {
        /// <summary>
        /// Method for processing custom attribute data.
        /// </summary>
        /// <param name="modelMetaData">A ModelMetaData instance.</param>
        public abstract void Process(ModelMetadata modelMetaData);
    }
    

    Make your attribute inherit from MetaDataAttribute :

    public class ToolTextAttribute : MetadataAttribute
    {
        public string Text { get; set; }
        public TooltextAttribute(string text)
        {
            this.Text = new text;
        }
    
        public override void Process(ModelMetadata modelMetaData)
        {
            modelMetaData.AdditionalValues.Add("ToolText", this.Text);
        }
    }
    

    Create the custom MetaDataProvider :

    public class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
        protected override ModelMetadata CreateMetadata(
            IEnumerable<Attribute> attributes,
            Type containerType,
            Func<object> modelAccessor,
            Type modelType,
            string propertyName)
        {
            var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            attributes.OfType<MetadataAttribute>().ToList().ForEach(x => x.Process(modelMetadata));
            return modelMetadata;
        }
    }
    

    And replace the default one (global.asax.cs) :

    protected void Application_Start()
    {
        // snipped
    
        ModelMetadataProviders.Current = new CustomModelMetadataProvider();
    }
    

    Finally, you can access it in your view (or in a Html Helper ) :

    (string)ViewData.ModelMetadata.AdditionalValues.Where(x => x.Key == "ToolText").SingleOrDefault()
    

    Source :

    • http://weblogs.asp.net/seanmcalinden/archive/2010/06/11/custom-asp-net-mvc-2-modelmetadataprovider-for-using-custom-view-model-attributes.aspx
    • http://weblogs.asp.net/seanmcalinden/archive/2010/06/12/asp-net-mvc-2-auto-complete-textbox-custom-view-model-attribute-amp-editortemplate.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the NerdDinner tutorial for MVC and have a question about setting up
I have simple question about MVC routing. How i can construct Html.ActionLink thhat generates
So here's a question about scheme variable binds. Let's say I have the following
I have the following question about JPA: Can I save the order of the
I have a question about variable scope in TCL, I have the following code:
I might have pretty basic question about regex. I have the following regex, which
I have a question about the following regular expression: I want to match the
I have a question about the following code in TCL/EXPECT: expect { timeout {
I have a question about the following C code: void my_function() { int i1;
I have a question about the following code : #include <iostream> #include <ctime> int

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.