ASP.NET MVC checkbox always false

Viewed 13437

I made an asp.net website, but the checkbox is always false. Why is this so?

Model:

 public string Username { get; set; }
 public string Password { get; set; }
 public bool Remember { get; set; }

CSHTML:

<div class="form-group">
    @Html.Label("Remember me?")
    @Html.CheckBoxFor(m => m.Remember)
 </div>

The Remember property is always false, if the checkbox is checked then Rememberis still false.

3 Answers

With Razor, I had the same problem. What worked for me was taking off the value="xxx" tag. Then it functioned normally.

Does not work:

 <input class="form-check-input" value="true" asp-for="Answer.aIsCorrect" />

Works:

 <input class="form-check-input" asp-for="Answer.aIsCorrect" />
Related