【发布时间】:2018-11-16 13:28:30
【问题描述】:
我正在使用 asp.net core 2.1,我有一个简单的视图,其形式如下:
@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>
如您所见,我有一个带有 IsRole 属性的复选框
所以在我的模型中我有一个布尔值:
public class ClaimToUserdModel
{
public string ClaimType { get; set; }
public string ClaimValue { get; set; }
public Guid UserId { get; set; }
public bool IsRole { get; set; }
}
然后在我调用的方法中:
public async Task<IActionResult> OnPost(ClaimToUserdModel model)
{
....
}
但它总是抛出错误,它不关心是否选中。我做错了什么?
【问题讨论】:
-
默认情况下,bool 为 false,除非您在代码中的某处将其设置为 true。
标签: c# asp.net asp.net-core asp.net-core-2.1