In the cshtml file, I have the following javascript in Home/Details/4
. 4 is the ID.
<script>
$(document).ready(function () {
$("#checkbox").click(function () {
$.post(
"Home/Toggle",
{ checkbox: $("#checkbox").val() },
function (data) {
});
});
});
</script>
The following is the action code in the controller.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Toggle(bool checkbox)
{
...... // How to get ID?
var x = db.XXXX.Find(id);
How to get the ID? From some routing data, or Url, or let the front jQuery posting pass it?
Is it possible to get the ID from the action method without passing from the front html page?