I'm using asp.net core 2.1 and I have a simple view with form like:
@model Security.WebUi.Pages.AssignClaimToUserModel
<form method="post">
<div>
<label>User: </label>
<select asp-for="UserId" asp-items="@Model.UserList">
<option>Please select one</option>
</select>
</div>
<div>
<label>Role?</label>
<input type="checkbox" name="IsRole" id="isRole" />
</div>
<div>
<label>Claim Type</label>
<input type="text" name="ClaimType" id="claimType" />
</div>
<div>
<label>Claim Value</label>
<input type="text" name="ClaimValue" />
</div>
<button type="submit">Submit</button>
</form>
As you can see I have a checkbox with IsRole property
So in my model I have a boolean:
public class ClaimToUserdModel
{
public string ClaimType { get; set; }
public string ClaimValue { get; set; }
public Guid UserId { get; set; }
public bool IsRole { get; set; }
}
then in method I call as:
public async Task<IActionResult> OnPost(ClaimToUserdModel model)
{
....
}
But it always throw false, it does not care about checked or not. What am I doing wrong?