Search code examples
c#htmlblazorreadonly

Blazor making a field read only


<div class="wrap-input100 validate-input">
    <span>County Code</span>
    <InputText class="@("cursor-disabled "+ input100)" readonly="true"  disabled="true" name="addressLine1" placeholder="County Code..." @bind-Value="_model.CountyCode" />
    <ValidationMessage For="@(() => _model.CountyCode)" />
</div>

I have the HTML attribute readonly and disabled But when the page is rendered, it does not respect this.


Solution

  • just use classic HTML tag <input> and add readonly ( but not readonly="true")

    <input type="text" class="@("cursor-disabled "+ input100)"  id="addressLine1" name="addressLine1" placeholder="County Code..." @bind-Value="_model.CountyCode" readonly />