You can use HTML onclick for this:
@Html.CheckBox("mycheckbox", new { onclick="triggerLink()" })
Use @Url.Action instead of @Html.ActionLink to get only the URL:
<script> function triggerLink() { var theUrl = '@Url.Action("SwitchTaskIsComplete", "Task", new {taskId = task.TaskId, isComplete = !task.IsComplete, userId = Model.UserId}, null)'; window.location = theUrl; } </script>
You can also put the entire inline expression in the attribute:
@{ var url = Url.Action("SwitchTaskIsComplete", "Task", new {taskId = task.TaskId, isComplete = !task.IsComplete, userId = Model.UserId}, null); } @Html.CheckBox("mycheckbox", new { onclick="window.location = '" + url + "'" })
source share