title: checked checkbox dynamically with value from database in mvc4
body: <p>I have made ​​a dynamic checkboxes based on existing data in the database. 
  For storage to the database, I use the id contained in each of checkboxes. the problem is, when I want to edit the data and returns the value of the checkboxes, the checkbox is not checked dynamically. 
  What I need to know is how to make the checkboxes checked dynamically when the edit page is loaded according to the id that is already stored in the database.</p>
  
  <p>here some of my code</p>
  
  <p>in Edit View </p>
  
  <pre><code>  @foreach (var item in Model.ModulList) // for generated dynamic checkboxes
  
     {
       &lt;tr&gt;
         &lt;td&gt;
  
          &lt;input type="checkbox" data-toggle="checkbox" name="SelectedModuls" Value ="@item.ModulID"&gt;@item.ModulName  // Got stuck in this session
  
  
         &lt;/td&gt;
        &lt;/tr&gt;
      }
  </code></pre>
  
  <p>in Controller</p>
  
  <pre><code> public ActionResult Edit(int id)
      {
         return View(DAM.GetMenuById(id));
      }
  </code></pre>
  
  <p>In Data Access Function GetMenuById(id)</p>
  
  <pre><code>public MenuModel GetMenuById(int id)
      {
          MenuModel menus = new MenuModel();
          menus.ModulList = GetModuleList();
          menus.StatusList = MenuStatus;
  
          try
          {
               string query = string.Format(@"SELECT DISTINCT M.MenuID, M.MenuName, Md.ModulID, Md.ModulName from Menu M
                                              LEFT JOIN MenuModul MM ON MM.MenuID = M.MenuID 
                                              LEFT JOIN Modul Md ON Md.ModulID = MM.ModulID 
                                              where M.MenuID = {0} AND M.IsDeleted = 0", id);
              SqlCommand cmd = new SqlCommand(query, conn);
              conn.Open();
  
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              DataTable dt = new DataTable();
  
              da.Fill(dt);
  
              for (int i = 0; i &lt;= dt.Rows.Count - 1; i++)
              {
                  menus.MenuID = Convert.ToInt32(dt.Rows[i]["MenuID"]);
                  menus.MenuName = Convert.ToString(dt.Rows[i]["MenuName"]);
                  menus.ModulID = Convert.ToInt32(dt.Rows[i]["ModulID"]);
                  menus.ModulName = Convert.ToString(dt.Rows[i]["ModulName"]);
              }
  
            // I fetch ModulID and ModulName data for return the checkbox value when I want to edit.
  
              da.Dispose();
          }
          catch (Exception e)
          {
              Console.WriteLine(e);
          }
          finally
          {
              conn.Close();
          }
  
          return menus;
      }
  </code></pre>
  
  <p>Please help, and I will be very grateful :)</p>