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? :)
This is my view:
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.section)
</td>
<td>
@Html.CheckBoxFor(modelItem => item.check, new { onclick = "SomeMethod(this)" });
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.idImovine })
</td>
</tr>
}
</table>
<script type="text/javascript">
function SomeMethod(checkboxInput) {
$.ajax({
type: 'POST',
url: 'Home/Action',
data: { newValue: checkboxInput.checked },
success: success,
dataType: 'json'
});
}
</script>
This is my controller
public JsonResult Action(bool newValue)
{
var model = con.pro.Single(r => r.id == id);
TryUpdateModel(model);
con.SubmitChanges();
return Json(true)
}
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.