I want to combine an input tag helper with razor code to set an attribute but I cannot get the two technologies to work together. I am simply trying to set the disabled attribute on the input field based on the value of view model property.
When i put the razor code after the asp-for
tag the razor intellisense is not recognized and the field is not disabled as expected...
<input asp-for="OtherDrugs" @((Model.OtherDrugs == null) ? "disabled" : "") class="form-control" />
Rendered output...
<input type="text" id="OtherDrugs" name="OtherDrugs" value="" />
When i put the razor code before the asp-for
tag the tag helper intellisense is not recognized and the field is not set with the view model properties as expected...
<input @((Model.OtherDrugs == null) ? "disabled" : "") asp-for="OtherDrug" class="form-control" />
Rendered output...
<input disabled asp-for="OtherDrugs" class="form-control" />
Note that combining tag helpers and razor does work if the razor code is inside a class attribute. Unfortunately input fields require the disabled attribute and not the disabled class for bootstrap 3.
Is there a way to make this work?