Q:

Html helper LabelFor doesn't render title (tooltip)

On my view i use html helper LabelFor.  Label Text sometimes is too long, so i set max-width for label.  Now it looks like this : 
Label for some fi... while the full text is Label for some field
So in this case will be greate to show title of label to see the full text. 
But standart html helper doesn't add title to html.  
How can i resolve my problem using html helpers? 

Example what i need without Html Helpers : http://jsfiddle.net/fdf5kx5z/4/

A:

You could create a custom html helper for this
using System;
using System. Collections. Generic;
using System. Linq. Expressions;
using System. Web. Mvc;
using System. Web. Mvc. Html;

namespace YourAssembly. Html
{
  public static class LabelHelpers
  {
    public static MvcHtmlString TooltipLabelFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression)
    {
      ModelMetadata metaData = ModelMetadata. FromLambdaExpression(expression, helper. ViewData);
      Dictionary<string, object> attributes = new Dictionary<string, object>();
      attributes. Add("title", metaData. GetDisplayName());
      return helper. LabelFor(expression, attributes);
    }
  }
}

and add a reference  to the <namespaces> section of web.config
<add namespace="YourAssembly. Html "/>

