最佳答案
在我的 ASP.NET MVC 应用程序中,我使用以下代码渲染了一个复选框:
<%= Html.CheckBoxFor(i=>i.ReceiveRSVPNotifications) %>
现在,我看到这将呈现 都有复选框输入标记和一个隐藏的输入标记。我遇到的问题是,当我尝试使用 FormCollection 从复选框检索值时:
FormValues["ReceiveRSVPNotifications"]
我得到了值“ true,false”:
<input id="ReceiveRSVPNotifications" name="ReceiveRSVPNotifications" value="true" type="checkbox">
<input name="ReceiveRSVPNotifications" value="false" type="hidden">
因此 FormValue 集合似乎将这两个值连接起来,因为它们具有相同的名称。
有什么想法吗?