Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Conditionally add attribute to

$
0
0

Hi,

I want to add a readonly="readonly" attribute to a input type text element based on something at runtime, this is what I have but it doesn't work :

<input asp-for="NoOfTelephoneNumbers" class="form-control" @if(!Model.FullEditing) {<text>readonly="readonly"</text>} />

However if it was an element with no asp- attributes then it is allowed :

<input type="text" name="NoOfTelephoneNumbers" @if (!Model.FullEditing) {<text>readonly="readonly"</text>} />

Obviously I can just have an if else statement and have 2 different <input as-for... elements but it seems a shame to repeat everything.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>