How to get checkbox value from FormCollection?

后端 未结 5 476
耶瑟儿~
耶瑟儿~ 2021-01-02 03:18

I have a checkbox and button:

@using(Html.BeginForm())
{
    
5条回答
  •  时光取名叫无心
    2021-01-02 03:41

    I had trouble getting this to work and this is the solution I came up with. I'm showing it with an html helper.

    @Html.CheckBoxFor(model => model.showAll, new { @class = "form-control", Name = "showAll"})
    

    This is where I kept falling down and the following works.

    bool MyBoolValue= (collection["showAll"] ?? "").Equals("true", StringComparison.CurrentCultureIgnoreCase);
    

提交回复
热议问题