Click here to Skip to main content
15,077,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Actually i tried alot to bind database value to checkboxlist in mvc.

I tried with below code, but got error like
CS0103: The name 'i' does not exist in the current context

 public class ClaimModel
        public List<ToolsIDCheck> ItemViewDataModel { get; set; }


    public class ToolsIDCheck
        public string ToolsName { get; set; }
        public int Toolsno { get; set; }
        public bool Selected { get; set; }


        public ActionResult Create(string model)

ClaimModel obj = new ClaimModel();
 obj.ItemViewDataModel = new List<ToolsIDCheck>();

            List<ClaimModel> choiceList = new List<ClaimModel>();
            DataSet ds2 = obj.BindTools();
             foreach (DataRow dr in ds2.Tables[0].Rows) // loop for adding add from dataset to list<modeldata>

                  obj.ItemViewDataModel.Add(new ToolsIDCheck
                    Toolsno = Convert.ToInt16(dr["tool_id"]),
                    ToolsName = dr["tools_name"].ToString()



@model CustomerPortal.Models.ClaimModel
@using (Html.BeginForm())

<div class="divnewtxt">

for (var i = 0; i < Model.ItemViewDataModel.Count; i++)
        @Html.HiddenFor(model => model.ItemViewDataModel[i].Toolsno)
        @Html.HiddenFor(model => model.ItemViewDataModel[i].ToolsName)           
        @Html.CheckBoxFor(model => model.ItemViewDataModel[i].Selected)
        @Html.DisplayFor(model => model.ItemViewDataModel[i].ToolsName)
    <br />
              }                  </div>

pls help for this issue.
How to bind this list value to checkboxlist and how to resolve this issue??

Pls suggest any other easy way to bind to checkboxlist in mvc razor too..
Updated 7-Oct-14 22:00pm

1 solution


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