title: input-validation-error class not added to custom HtmlHelper Extension Method
body: <p>I wrote my own HtmlHelper Extension Method to display a time-input.</p>
  
  <pre><code>public static MvcHtmlString TimePickerFor&lt;TModel, TProperty&gt;(this HtmlHelper&lt;TModel&gt; htmlHelper, Expression&lt;Func&lt;TModel, TProperty&gt;&gt; expression)
          {
              if (expression == null)
              {
                  throw new ArgumentNullException("expression");
              }
  
              string expressionText = ExpressionHelper.GetExpressionText(expression);
              string value = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData).Model.ToString();
              return TimePicker(htmlHelper, expressionText, value);
          }
  
          public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, string value)
          {
              TagBuilder builder = new TagBuilder("input");
              builder.MergeAttribute("type", "time");
              builder.MergeAttribute("id", name);
              builder.MergeAttribute("name", name);
  
              if (value != null)
              {
                  builder.MergeAttribute("value", value);
              }
  
              return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
          }
  </code></pre>
  
  <p>This is how I use it:</p>
  
  <pre><code>@Html.TimePickerFor(model =&gt; model.StartTime)
  </code></pre>
  
  <p>When the time is not valid, I add an error like this:</p>
  
  <pre><code>ModelState.AddModelError("StartTime", "The selected time is already taken.");
  </code></pre>
  
  <p>When this error is added, it should add the <code>input-validation-error</code> class to the input, but it doesn't. I cannot get it to work. It does show the error in the <code>ValidationSummary</code>, and it adds the class to the default inputs. Any help would be appreciated!</p>
  
  <p>I already tried adding it like this, but this still won't add the class: </p>
  
  <pre><code>var validation = helper.GetUnobtrusiveValidationAttributes(name);
  foreach (KeyValuePair&lt;string, Object&gt; attribute in validation)
  {
      builder.MergeAttribute(attribute.Key, attribute.Value.ToString());
  }
  </code></pre>
  
  <p><strong>Edit:</strong> temporary workaround found, haven't been able to solve the problem though</p>
  
  <pre><code>ModelState modelState;
  if (helper.ViewData.ModelState.TryGetValue(name, out modelState))
  {
      if (modelState.Errors.Count &gt; 0)
           builder.AddCssClass("input-validation-error");
  }
  </code></pre>