Asp.net mvc c # tooltip

what is the best and easiest way to create tooltip text for text fields

+4
source share
3 answers

With JavaScript and probably with a framework like jQuery, which works very well for ASP.NET MVC. Using the framework means that someone has already done the hard work and wrote a plugin for it!

Of course, there is a title attribute in text inputs that appears as a tooltip in some browsers.

+3
source

I found this to be the easiest and most convenient approach:

  • Creating a description using data annotation for a property of your model Example:

    [Display(Name="MyTextBox", Description = "Title for your entry")] public string MyTextBox{ get; set; }

  • Then in your view, go to the description above using:

    @Html.TextBoxFor(model => model.MyTextBox, new { title = ModelMetadata.FromLambdaExpression(model => model.MyTextBox, ViewData ).Description })

+2
source

Use data annotations in your model to place a tooltip in the Description property of the DisplayAttribute attribute.

Then create your own Html Helper function that places the Description property in the title attribute of the TextBox input field. You can call the TextBoxWithTooltipFor helper

In your definition, you can replace the call with @ (Html.TextBoxFor (...)) with the call @ (Html.TextBoxWithTooltipFor (...))

Here is the code that has been tested and works. Picture of code to add tooltip to textbox

0
source

All Articles