[英]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.