Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to bind a checkbox in MVC2 using classes.I also need to know how to get the selected value of the checkbox in post action.I am pretty new to MVC so please give me a detailed explanation.Thank you.
Posted
Updated 17-Sep-12 1:00am
v2

1 solution

You can try like below

In Your View Page

XML
<% using (Html.BeginForm())
      {%>




           <input type="checkbox" name="week" value="Sunday"  />Sunday
           <input type="checkbox" name="week" value="Monday" />Monday
           <input type="checkbox" name="week" value="Teusday" />Teusday
           <input type="checkbox" name="week" value="Wednesday"  />Wednesday
           <input type="checkbox" name="week" value="Thursday" />Thursday
           <input type="checkbox" name="week" value="Friday" />Friday
           <input type="checkbox" name="week" value="Saturday" />Saturday
           <input type="submit" value="post" />
           <%}%>



And

in your controller
SQL
public ActionResult Index(FormCollection cs, string[] week)
        {
            string[] selectedcheckoxes = week;
           // your code goes here
            return View();
        }
 
Share this answer
 

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