title: MVC 3 Saving checkbox state in db
body: <p>I have one problem i am hoping someone will have time to look at. I have view as table in my mvc 3 test project. Inside table there is checkbox. I am trying to have that checkboxes to be saved whenever i click on them. I tried with java script, tried with lots of examples from internet but still no luck for me. Can someone help? :)</p>
  
  <p>This is my view:</p>
  
  <pre><code>@foreach (var item in Model)
  {
      &lt;tr&gt;
  
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.date)
          &lt;/td&gt;
  
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Name)
          &lt;/td&gt;
  
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.section)
          &lt;/td&gt;
          &lt;td&gt;
  
    @Html.CheckBoxFor(modelItem =&gt; item.check, new { onclick = "SomeMethod(this)" });
  
  &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id = item.idImovine }) 
  
             &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
     function SomeMethod(checkboxInput) {
  
          $.ajax({
              type: 'POST',
              url: 'Home/Action',
              data: { newValue: checkboxInput.checked },
              success: success,
              dataType: 'json'
          });
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my controller</p>
  
  <pre><code>   public JsonResult Action(bool newValue)
          {
  
              var model = con.pro.Single(r =&gt; r.id == id);
  
  
              TryUpdateModel(model);
              con.SubmitChanges();
  
              return Json(true)
  
  
          }
  </code></pre>
  
  <p>I am using linq to sql for access to db. Can someone tell me what i am doing wrong, my intention is to have checkbox saved in dv whenever it is clicked, but that checkbox is getting clicked in a table which is coming from view and it needs to be saved to another tabe, so i am guessing i need to pass id which is inside view too, along with checkbox value.</p>