Why do my checkboxes not pass their value to my controller in ASP.NET Core?

后端 未结 3 1068
闹比i
闹比i 2021-01-14 13:49

I feel this may be an easy fix but I cannot seem to get around it. I have an ASP.NET Core web application and I\'m using an ajax form to submit data to my controller for pr

3条回答
  •  无人共我
    2021-01-14 14:34

    If not using asp-for attribute , you can modify your codes to add a hidden field. It will be submitted regardless whether the checkbox is checked or not. If the checkbox is checked, the posted value will be true,false. The model binder will correctly extract true from the value. Otherwise it will be false :

    
    
    
    

提交回复
热议问题