How to save checkbox checked values in database.

Posted by Sampath1750 under ASP.NET on 3/29/2012 | Points: 10 | Views : 7891 | Status : [Member] | Replies : 5
How to save checkbox values in database.

Below is my view code.

@foreach (var item in Model)

{

@Html.CheckBox("statecheck", (IEnumerable<SelectListItem>)ViewData["StatesList"])
@Html.DisplayFor(modelItem => item.state_name)

</br>

}

<input class="ASPbutton" type="submit" value="submit"/>



Below is My controller.

public ActionResult States()

{

ViewData["StatesList"] = new SelectList(am.FindUpcomingStates().ToList(), "state_id", "state_Name");

return View();

}



My model is


public IQueryable<state> FindUpcomingStates()

{

return from state in Adm.states orderby state.state_name select state;


}


After clicking submit button checked item state_id will be saved into database.


I wrote like below in Controller, but i got true or false values, i want state_id<pre lang="c#">
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult States(string _stateName, char[] statecheck, FormCollection formvalues)
{
statecheck = Request.Form["statecheck"].ToArray();
ViewData["StatesList"] = new SelectList(am.FindUpcomingStates222().ToList(), "state_id", "state_Name");
}



Thanks,




Responses

Posted by: Sakthi.Singaravel on: 4/13/2012 [Member] Silver | Points: 25

Up
0
Down
Refer thi slink..

http://forums.asp.net/post/4904523.aspx

Regards,
Singaravel M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/16/2012 [Member] Bronze | Points: 25

Up
0
Down
http://pastebin.com/wBKchjc0

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/16/2012 [Member] Bronze | Points: 25

Up
0
Down
Nice source man
http://www.coderanch.com/t/284951/JSP/java/save-checked-value-checkbox-database

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/16/2012 [Member] Silver | Points: 25

Up
0
Down
r u got solution...?

Regards,
Singaravel M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/16/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.codingforums.com/showthread.php?t=214541

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Sampath1750, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response