Click here to Skip to main content
15,916,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
My view code is :
C#
@using(Html.BeginForm("submit","Security",FormMethod.Post)) 
{ 

@foreach (var item in Model.app_function) 

{ 

 <input type="checkbox" name="Functioncheck" value="@item.app_function_id"/> 
                    @Html.Encode(item.app_function_name)

}

    <input type="submit" value="submit" /> 
} 

after click submit button checked values are saved into database, but checked values are unchecked.

My controller code is:
C#
[AcceptVerbs(HttpVerbs.Post)]
        public ViewResult submit(FormCollection fm)
        {

                    string Roleecheck = Request.Form["Functioncheck"].ToString();
                    string[] x = Roleecheck.Split(',');
                    int a = Convert.ToInt32(x.Length);
                    for (int i = 0; i < x.Length; i++)
                    {
                        int userid = Convert.ToInt32(x[i]);
                        var myEntity = new user_role { role_id = id, user_id = userid, created_date = DateTime.Now, created_by = 1 };
                        UpdateModel(myEntity);
                        am.Add(myEntity);
                    }
                    am.Save();

return view();

        }


Give me some idea for how to set checkbox checked items, after click submit.

Thanks.
Posted
Updated 4-Jun-12 1:22am
v2
Comments
AmitGajjar 4-Jun-12 7:23am    
<pre> tag added.

1 solution

What have you written in your page_load event? I think this issue will be solved, if you check page.ispostback.

Regards
Sebastian
 
Share this answer
 
Comments
sampath1750 4-Jun-12 7:57am    
In mvc3 we wont add page_load event
Sebastian T Xavier 4-Jun-12 8:19am    
oh I am sorry. But you didn't specified its in mvc3.
sampath1750 4-Jun-12 8:46am    
Ok

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