title: ASP.Net Core Conditional Class Tag Helper
body: <p>When implementing the solution to an <a href="https://stackoverflow.com/a/42385059/1108740">existing question</a> for a conditional class tag helper in ASP.Net Core 2.0 I am not getting the expected results.</p>
  
  <p>The tag helper is a direct copy from the posted answer and has not been modified.</p>
  
  <p>Following the example instead of the class name I'm getting the full attribute name along with the specified class.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>TagHelper</p>
  
  <pre><code>using Microsoft.AspNetCore.Razor.TagHelpers;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  
  namespace PerformanceTools.TagHelpers
  {
      [HtmlTargetElement("div", Attributes = ClassPrefix + "*")]
      public class ConditionClassTagHelper : TagHelper
      {
          private const string ClassPrefix = "condition-class-";
  
          [HtmlAttributeName("class")]
          public string CssClass { get; set; }
  
          private IDictionary&lt;string, bool&gt; _classValues;
  
          [HtmlAttributeName("", DictionaryAttributePrefix = ClassPrefix)]
          public IDictionary&lt;string, bool&gt; ClassValues
          {
              get
              {
                  return _classValues ?? (_classValues = new Dictionary&lt;string, bool&gt;(StringComparer.OrdinalIgnoreCase));
              }
              set
              {
                  _classValues = value;
              }
          }
  
          public override void Process(TagHelperContext context, TagHelperOutput output)
          {
              var items = _classValues.Where(e =&gt; e.Value).Select(e =&gt; e.Key).ToList();
  
              if (!string.IsNullOrEmpty(CssClass))
              {
                  items.Insert(0, CssClass);
              }
  
              if (items.Any())
              {
                  var classes = string.Join(" ", items.ToArray());
  
                  output.Attributes.Add("class", classes);
              }
          }
      }
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public IActionResult ConditionalTest()
  {
      List&lt;ConditionalTestViewModel&gt; model = new List&lt;ConditionalTestViewModel&gt;();
      model.Add(new ConditionalTestViewModel { Active = true });
      model.Add(new ConditionalTestViewModel { Active = false });
      return View("ConditionalTest", model);
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>public class ConditionalTestViewModel
  {
      public bool Active { get; set; }
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model IEnumerable&lt;ConditionalTestViewModel&gt;
  
  &lt;div&gt;Conditional Test&lt;/div&gt;
  @foreach(var c in Model)
  {
      &lt;div condition-class-active="@c.Active"&gt;@c.Active&lt;/div&gt;
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>&lt;div id="container-body" class="container"&gt;
  
  &lt;div&gt;Conditional Test&lt;/div&gt;
      &lt;div condition-class-active="conditional-class-active"&gt;True&lt;/div&gt;
      &lt;div&gt;False&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Update:</strong> As pointed out the TagHelper is <code>condition-class-*</code> not <code>conditional-class-*</code>, I have updated my question with this but the issue still remains.</p>