I want to enable or disable a textarea depending on a condition that evalueates from the model, and I am using the textarea tag helper.
In other words, something like this:
<textarea asp-for="Doc" @(Model.MustDisable ? "disabled" : "")></textarea>
But I got the following design-time error: The tag helper 'textarea' must not have C# in element's attribute declaration area.
Then I tried:
<textarea asp-for="Doc" disabled='@(Model.MustDisable ? "disabled" : "")'></textarea>
which did not show any design time error but it renders like this:
Model.MustDisable==true
renders disabled='disabled'
AND Model.MustDisable==false
renders disabled
.
So the text area will always be disabled.
Then I tried (removing the 's):
textarea asp-for="Doc" disabled=@(Model.MustDisable ? "disabled" : "")></textarea>
which did not show any design time error but it renders the same as the previous one.
How can I implement this the right way?
question from:
https://stackoverflow.com/questions/34866539/asp-net-conditionally-disable-a-tag-helper-textarea 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…