ASP.NET MVC:Why does the CheckBoxFor render an additional input tag and how can I get the value usin
        Posted  
        
            by Nikron
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nikron
        
        
        
        Published on 2010-05-18T20:34:52Z
        Indexed on 
            2010/05/18
            20:40 UTC
        
        
        Read the original article
        Hit count: 1117
        
ASP.NET
|asp.net-mvc
Hi, In my ASP.NET MVC app I am rendering out a checkbox using the following code:
<%= Html.CheckBoxFor(i=>i.ReceiveRSVPNotifications) %>
Now I see that this renders both the checkbox input tag and a hidden input tag. The problem that I am having is when I try retrieve the value from the checkbox using the FormCollection:
FormValues["ReceiveRSVPNotifications"]
I get the value "true,false". When looking at the rendered out HTML I can see the following:
 <input id="ReceiveRSVPNotifications" name="ReceiveRSVPNotifications" value="true" type="checkbox">
 <input name="ReceiveRSVPNotifications" value="false" type="hidden">
So the FormValues collection seems to join these two values since they have the same name. Any Ideas?
© Stack Overflow or respective owner