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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:33:20+00:00 2026-05-31T01:33:20+00:00

I created attribute class to attach metadata to properties, so I can display tooltips

  • 0

I created attribute class to attach metadata to properties, so I can display tooltips for the form’s input fields.

HelpAttribute implements IMetadataAware:

Public Class HelpAttribute
    Inherits Attribute
    Implements System.Web.Mvc.IMetadataAware

    Public Sub New(text As String)
        _text = text
    End Sub

    Private _text As String
    Public ReadOnly Property Text As String
        Get
            Return _text
        End Get
    End Property

    Public Sub OnMetadataCreated(metadata As System.Web.Mvc.ModelMetadata) Implements System.Web.Mvc.IMetadataAware.OnMetadataCreated
        metadata.AdditionalValues.Add("HelpText", _text)
    End Sub
End Class

I utilize this metadata in my extension method:

<Extension()>
Public Function HelpFor(Of TModel, TProperty)(ByVal htmlHelper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty))) As MvcHtmlString
    Dim metaData = ModelMetadata.FromLambdaExpression(Of TModel, TProperty)(expression, htmlHelper.ViewData)

    If metaData.AdditionalValues.ContainsKey("HelpText") Then
        Dim helpText = metaData.AdditionalValues("HelpText")
        Return MvcHtmlString.Create(String.Format("<span class=""help""></span><div class=""tooltip"" style=""display: none""><div class=""border-top""></div><div class=""close""><a href=""#"">close</a></div><br class=""clear""><div class=""content"">{1}</div></div>", htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(metaData.PropertyName), helpText, metaData.DisplayName))
    End If

    Return MvcHtmlString.Create(String.Format("<span class=""no_help""></span>", htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(metaData.PropertyName), metaData.DisplayName))
End Function

So I can call Html.HelpFor for any of my model’s properties and if it has appropriate metadata I display a help icon which shows the tooltip on click (js).

That all works fine as long as HelpAttribute is defined in the same assembly as the classes that I decorate their properties with. Today I had to move HelpAttribute to a separate dll (different namespace as well), so I did that, I referenced the project and expected it to work. I do not get any compiler errors, the app works fine, but it does not display the help icons. I debuggedd the code and I see that the constructor of HelpAttribute is called for different properties with a proper text, but OnMetadataCreated is never called. Does anyone have an idea why that is and how to fix it?

  • 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-31T01:33:21+00:00Added an answer on May 31, 2026 at 1:33 am

    Once again I will answer my question myself. Apparently posting things on SO helps me structure the problem in my head. When I moved HelpAttribute to a seperate class library I had to reference System.Web.Mvc for IMetadataAware interface. I use .NET 4.0 and I automatically referenced MVC4 that I installed some time ago for testing purposes. It didn’t get me any errors, it just did not work. When I changed System.web.Mvc to ver. 3.0 everything works smoothly.

    • 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 have created a Custom Validation Attribute: public sealed class DateAttribute : DataTypeAttribute {
I created an ArticleController to render a form with fields: title (text) and content
I've created a simple Attribute: [AttributeUsage(AttributeTargets.Method)] public class InitAttribute : System.Attribute { public InitAttribute()
if i have created an attribute: public class TableAttribute : Attribute { public string
I've created attribute like [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] [Serializable] public class TestPropertyAttribute : System.Attribute
I have created an Attribute, call MyAttribute, which is performing some security and for
I created a simple custom attribute on the sales/order entity. Now, for new orders,
Where does Railo store files created by when using the file attribute? I.e. <cflog
I'm trying to add the jVal attribute to a textbox that I created 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.