asp.net conditionally disable a tag helper (textarea)

It is actually very simple, the disable attribute is already working as you want – you can pass in a boolean value:

<textarea asp-for="Doc" disabled="@Model.MustDisable"></textarea>

if false the disabled attribute is not rendered:

<textarea></textarea>

if true the disabled attribute is set to “disabled”:

<textarea disabled="disabled"></textarea>

Leave a Comment