title: how to get selected checkbox in asp.net using entity framework
body: <p>i'm new to asp.net mvc.I have a list of checkboxes and i want when the checkboxes are selected a new list of selected checkboxs are shown.
  my code Product.cs code:</p>
  
  <pre><code>public class Product
  {
      public int ProductID { get; set; }
      public string ProductName { get; set; }
      public int Price { get; set; }
      public bool Checked { get; set; }
      public virtual ICollection&lt;Purchase&gt; Purchases { get; set; }
  }
  </code></pre>
  
  <p>My view: </p>
  
  <pre><code>&lt;h2&gt;Product Lists&lt;/h2&gt;
  @using (Html.BeginForm())
  {
  
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  Product ID
              &lt;/th&gt;
              &lt;th&gt;
                  Product Name
              &lt;/th&gt;
              &lt;th&gt;
                  Price
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
          @for (var i = 0; i &lt; Model.Count(); i++)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(x =&gt; x[i].ProductID)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(x =&gt; x[i].ProductName)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(x =&gt; x[i].Price)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.CheckBoxFor(x =&gt; x[i].Checked, new { Style = "vertical-align:3px}" })
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
  
      &lt;/table&gt;
  
      &lt;input type="submit" value="Purchase" class="btn btn-default" /&gt;
  }
  </code></pre>
  
  <p>This is my Controller code.I want when the check boxes are selected in a new page the selected check boxes are shown.
      my ActionResult:</p>
  
  <pre><code>    public ActionResult Index()
      {
          return View(db.Products.ToList());
      }
  
      [HttpPost]
      public ActionResult Index(List&lt;Product&gt; list)
      {
          return View(list);
      }
  @using (Html.BeginForm())
  </code></pre>
  
  <p>{</p>
  
  <pre><code>&lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              Product ID
          &lt;/th&gt;
          &lt;th&gt;
              Product Name
          &lt;/th&gt;
          &lt;th&gt;
              Price
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @for (var i = 0; i &lt; Model.Count(); i++)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(x =&gt; x[i].ProductID)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(x =&gt; x[i].ProductName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(x =&gt; x[i].Price)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.CheckBoxFor(x =&gt; x[i].Checked, new { Style = "vertical-align:3px}" })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  
  &lt;/table&gt;
  </code></pre>