Click here to Skip to main content
15,902,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a Checkbox on view as
HTML
@Html.CheckBox("CB_ReportStatus", true);


And i am accessing it on my controllers method as

C#
bool CBValue = Convert.ToBoolean(Request.Form.Get("CB_ReportStatus"));


But in this case Convert.ToBoolean(Request.Form.Get("CB_ReportStatus"))

gives two values i.e true and false; which causes to error in controller.


How can i access checkbox exact selected value? and why two values appears in controller ?

Any help would be great for me...

thanks in advance
Posted

View your HTML. Do you have two checkboxes with the same name and one is checked and one is not ?
 
Share this answer
 
It can possible in controller as
C#
Server.HtmlEncode(Request.Form.Get("CB_ReportStatus")).Contains("true");
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900