Checkbox not working with boolean viewmodel property

后端 未结 4 1102
半阙折子戏
半阙折子戏 2021-02-12 13:02

I am using MVC6 and have a checkbox input field in my form, but when the form is submitted the value for the checkbox always gets passed to the ViewModel as false:

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-12 13:23

    Pinki's answer above is good if the checkbox should default to checked.

    If the checkbox should default to unchecked, a little in-line javascript sets the value to true or false upon clicking:

    
    

提交回复
热议问题