Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor (server) <input value=foo /> doesn't work for checkboxes #18306

Trolldemorted opened this issue Jan 12, 2020 · 5 comments

Blazor (server) <input value=foo /> doesn't work for checkboxes #18306

Trolldemorted opened this issue Jan 12, 2020 · 5 comments


Copy link

@Trolldemorted Trolldemorted commented Jan 12, 2020

Describe the bug

I am using @SteveSandersonMS 's workaround shown here, but it doesn't work for checkboxes. Take this snippet:

<input @key="@cat.Id" type="checkbox" value="@cat.IsBlack"
    @onchange=@(eventArgs => { cat.IsBlack= (bool)eventArgs.Value; HandleCatColor(cat); }) />

I assumed that the initial state of the checkbox would match the cat's property, but it is always unchecked, even if cat.IsBlack is true.

To Reproduce

Use the workaround with a checkbox.

Further technical details

PS C:\Users\Benni\repositories\ChallengePad> dotnet --info
.NET Core SDK (gemäß "global.json"):
 Version:   3.1.100
 Commit:    cd82f021f4

 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  3.0.100-preview9-014004 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview9.19424.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:

VS 2019 16.4.2


This comment has been minimized.

Copy link

@javiercn javiercn commented Jan 13, 2020

@Trolldemorted thanks for contacting us.

Do you happen to be prerendering?


This comment has been minimized.

Copy link

@Trolldemorted Trolldemorted commented Jan 13, 2020

It is on by default, right? Then yes.


This comment has been minimized.

Copy link

@SteveSandersonMS SteveSandersonMS commented Jan 13, 2020

The checked state of a checkbox is controlled by its checked attribute, not by a value attribute. This is an aspect of HTML, not Blazor specifically. So the code you want looks like this:

<input type="checkbox" checked="@cat.IsBlack"
    @onchange=@(eventArgs => { cat.IsBlack= (bool)eventArgs.Value; HandleCatColor(cat); }) />

This comment has been minimized.

Copy link

@mkArtakMSFT mkArtakMSFT commented Jan 13, 2020

We'll collect feedback similar to this at #18317


This comment has been minimized.

Copy link

@Trolldemorted Trolldemorted commented Jan 13, 2020

Thanks for the explanation, and I agree #18317 is a good idea - since html's checked cannot be set to false I assumed blazor's could not either!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.