title: Why Is My Razor Code Not Working With Tag Helpers in ASP.NET Core
body: <p>My question up front is why will razor syntax not work inside of a tag where I am using tag helpers? It is something I can work around and a solution to the problem has been answered <a href="https://stackoverflow.com/questions/40487688/asp-net-core-input-tag-helper-not-working-with-razor-code">HERE</a>, but I still have not been able to find out why this problem occurs.</p>
  
  <hr>
  
  <p>As an example of this I have a select tag that I am trying to add a disabled attribute to only if the model has a certain property. Here is the html:</p>
  
  <pre><code>&lt;select 
    @(Model.Id != 0 ? "disabled" : "") 
    asp-for="QuestionType" 
    asp-items="Html.GetEnumSelectList&lt;Enums.QuestionTypes&gt;()" 
    id="form-type" data-parsley-required class="form-control"&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Using Razor inside of the select outputs the following </p>
  
  <pre><code>&lt;select 
    asp-for="QuestionType" 
    asp-items="Html.GetEnumSelectList&lt;Enums.QuestionTypes&gt;()" 
    id="form-type" data-parsley-required="" class="form-control"&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Not using Razor gives this</p>
  
  <pre><code>&lt;select 
    id="form-type" data-parsley-required="" class="form-control" 
    data-val="true" data-val-required="The QuestionType field is required." 
    name="QuestionType"&gt;
    &lt;option selected="selected" value="0"&gt;Drop Down&lt;/option&gt;
    &lt;option value="10"&gt;Free Response&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <hr>
  
  <p>While using Razor syntax, it seems to ignore the tag helpers and does not build the HTML as it should (or as is expected). However, using razor inside of attribute values seems to work fine, it's when I use it to try and add things like tag attributes that I get these issues. As stated before, I am just trying to understand why this is happening.</p>