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

asp.net core razor page checkboxes model binding (always false)

$
0
0

i have a razor page in asp.net core with the following input tag:

<input asp-for="chkPref" />

in the code-behind i have:

public bool chkPref { getset; }

so when i run the app, i can confirm in `Request.Form` that I'm getting...

checkbox checked = {true,false}

checkbox unchecked = {false}

which is expected, according to https://www.learnrazorpages.com/razor-pages/forms/checkboxes

however, that page states that the model binding will figure out that `{true,false}` is actually `true` but i'm getting `false` no matter what.

the website above alludes to the fact that this "just happens"...

If the checkbox is checked, the posted value will be true,false. The model binder will correctly extract true from the value. Otherwise it will be false.

but that doesn't seem to be working, or at least isn't that obvious how it works.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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