Why does ASP.NET MVC Html.CheckBox output two INPUTs with the same name?

后端 未结 7 817
不知归路
不知归路 2020-12-03 17:07

Why in the world does the line:

<%= Html.CheckBox(\"ForSale\", Model.Product.ForSale)%> For Sale

result in the following HTML:

<
7条回答
  •  半阙折子戏
    2020-12-03 17:13

    It forces the field to be included if it's unchecked. If you uncheck a check box it doesn't get sent as part of the page - they are only sent if they're checked, and then there's a value of true. The hidden field ensures that false will be send if the check box is unchecked, as the hidden field is always sent.

提交回复
热议问题