Checkbox not working with boolean viewmodel property

后端 未结 4 1097
半阙折子戏
半阙折子戏 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:32

    input type checkbox sends an "on" if it is set. Otherwise it is not sent. It is important, that you set the value attribute to true. In this case it sends true or nothing, which is perfect to bind to a boolean.

    
    

提交回复
热议问题