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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:40:42+00:00 2026-05-16T22:40:42+00:00

As well as DisplayName eg. [DisplayName(Address line 1 )] public string Address1{get; set;} Html.LabelFor(model

  • 0

As well as DisplayName eg.

[DisplayName("Address line 1 ")]
public string Address1{get; set;}

Html.LabelFor(model => model.Address1) 

I have a requirement to show tooltips eg.

[DisplayName("Address line 1 ")]
[ToolTip("The first line of your address as it appears on you bank statement")]
public string Address1{get; set;}

Html.LabelFor(model => model.Address1) 
Html.ToolTipFor(model => model.Address1) 

Can I extend the DisplayName DataAnnotation to do this? I can’t see how it can be done.

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-16T22:40:43+00:00Added an answer on May 16, 2026 at 10:40 pm

    This is how I would do it. Time for some Champions League, I can clarify the code tomorrow if you want.

    First a attribute:

    public class TooltipAttribute : DescriptionAttribute
    {
        public TooltipAttribute()
            : base("")
        {
    
        }
    
        public TooltipAttribute(string description)
            : base(description)
        {
    
        }
    }
    

    And then a html helper to allow us to write Html.TooltipFor():

    public static class HtmlHelpers
    {
        public static MvcHtmlString ToolTipFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
        {
            var exp = (MemberExpression)expression.Body;
            foreach (Attribute attribute in exp.Expression.Type.GetProperty(ex.Member.Name).GetCustomAttributes(false))
            {
                if (typeof(TooltipAttribute) == attribute.GetType())
                {
                    return MvcHtmlString.Create(((TooltipAttribute)attribute).Description);
                }
            }
            return MvcHtmlString.Create("");
        }
    }
    

    Usage would then be this:

    Your model:

    public class User
    {
        [Tooltip("This is the attribute for FirstName")]
        public string FirstName { get; set; }
    }
    

    And in your view:

    <%= Html.ToolTipFor(x => x.FirstName) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some Well-Attributed DB code, like so: [Display(Name = Phone Number)] public string
Well i have a transparent div or the background is set to transparent :)
We have a public calendar for our company set up in an Exchange 2007
Well, I have a class Customer (no base class). I need to cast from
Well i have a gridview where i have defined the columns on my own
I have the following servlet code public void doPost(HttpServletRequest request, HttpServletResponse response){ Backup bup
I have been using DataVisualization.Charting.Chart to produce few charts. Everything works very well, until
Using ASP.NET MVC 3, I have been struggling to set the selected value for
I have a Helper method like this to get me the PropertyName (trying to
Well I am using the following code to take any old image into a

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.