How to submit unchecked checkbox also

后端 未结 6 1297
滥情空心
滥情空心 2020-12-17 16:56

If checkbox is not checked, clicking on form submit button does not submit any data.

Some checkboxes may be not present in form depending on form fields selected by

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 17:15

    This is a common issue with checkboxes in HTML forms and isn't unique to ASP.NET.

    The answer is to have a hidden field that accompanies each checkbox. When the checkbox is modified, use a client-side event to update the hidden field.

    The hidden field will always be submitted.

    However, since you're using ASP.NET MVC, if you use the HTML.CheckBoxFor helper, it will handle this for you automatically.

提交回复
热议问题