Aspnetcore: No way to bind <input readonly />

Created on 12 May 2018  路  3Comments  路  Source: dotnet/aspnetcore

There is no way to bind an input readonly attribute to a bool.

This results in the following code abomination:

@if (Readonly)
{
    <input readonly type="@InputType" class="form-control" aria-describedby="emailHelp" placeholder="@Placeholder" value="@Value" onchange="@ItChanged" />
}
else
{
    <input type="@InputType" class="form-control" aria-describedby="emailHelp" placeholder="@Placeholder" value="@Value" onchange="@ItChanged" />
}
area-blazor

Most helpful comment

This is working fine

 <input type="text" readonly=@true/>
 <input type="text" readonly=@false/>

All 3 comments

To generalize this:
the following construct

<input type="text" @(true ? "readonly" : "") />

results in

Error BL9980 Expressions like 'true ? "readonly" : ""' inside of a tag must be part of an attribute. Previous releases of Blazor supported constructs like '@onclick(...)' or '@bind(...)'.These features have been changed to use attribute syntax. Use 'onclick="@..."' or 'bind="..." respectively.

This is working fine

 <input type="text" readonly=@true/>
 <input type="text" readonly=@false/>

(facepalm) - you're right - thanks Mihail!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pixel-Lord picture Pixel-Lord  路  3Comments

rbanks54 picture rbanks54  路  3Comments

markrendle picture markrendle  路  3Comments

ermithun picture ermithun  路  3Comments

farhadibehnam picture farhadibehnam  路  3Comments