How to retrieve checkboxlist values in the controller in asp.net mvc
Posted
by sukumar
on Stack Overflow
See other posts from Stack Overflow
or by sukumar
Published on 2010-04-23T19:13:54Z
Indexed on
2010/04/23
19:23 UTC
Read the original article
Hit count: 270
I am having a form in a view page that looks as below:
<form runat="server" id="dcrsubmit">
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>test1</asp:ListItem>
<asp:ListItem>test2</asp:ListItem>
<asp:ListItem>test3</asp:ListItem>
<asp:ListItem>test4</asp:ListItem>
<asp:ListItem>test5</asp:ListItem>
<asp:ListItem>test6</asp:ListItem>
</asp:CheckBoxList>
....other controls
</form>
Now when the form is posted, I am trying to retrieve the values submitted in the controller as below:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult testmethod(FormCollection formValues)
{
string s = formvalues.get("CheckBoxList1");
.
. /* other code */
.
}
The string value shows null when I submit the form by checking some checkboxes. Is this the way to retrieve the values or am I doing something wrong? And I cannot use html control because all other controls on the form are server controls and I am not sure if I can only make this control a html control. And I am not sure how can I bind the values to it?
© Stack Overflow or respective owner