[英]How do I check if a checkbox is checked on the controller page MVC5
这是cshtml页面
<div class="form-group">
@Html.Label("Please tick this box if you are signing up as a Student")
@Html.CheckBoxFor(m => m.isNewlyEnrolled)
</div>
我想检查控制器页面中是否检查了它。 我该怎么做呢?
通过向表单的提交端点添加名为IsNewlyEnrolled
(不区分大小写)的布尔参数,将使用复选框的状态填充它。
public HttpResponseMessage MyEndpoint(bool isNewlyEnrolled) {
// true == checked
// false == unchecked
}
或者,如果您接受复杂模型,请使用相同名称向该模型添加字段/属性。
public class MyModel
{
public bool IsNewlyEnrolled { get; set; }
}
public HttpResponseMessage MyEndpoint(MyModel model) {
// true == checked
// false == unchecked
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.