I am trying to pass the state of multiple checkboxes as a string (updated by JS when someone checks a box) when a form is submitted, rather than iterate through each value in the controller. What am I doing wrong? I tried:
@model UserClaimsViewModel;
<script>
function callme(val) {
var t = "";
$('#MyDiv input:checked').each(function () {
t += this + ",";
});
@Model.CoIDs=t;
@Html.HiddenFor(m => m.CoIDs);
console.log("coids updated to: " +@Model.CoIDs);
}
</script>
@Model.email
<br />
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.email)
<div class="panel-body" id="MyDiv">
<table>
@foreach (var t in Model.CoIDs.Split(','))
{
<tr>
<td>
<input type="checkbox" onchange="callme(@t)" name="@t" id="@t">@t
</td>
</tr>
}
</table>
</div>
<input type="submit" value="Submit Changes" />
}
Error:
UserClaimEditView?userEmail=a@gmail.com:78 Uncaught ReferenceError: Invalid left-hand side in assignment
Error after checking checkbox:
UserClaimEditView?userEmail=a@gmail.com:65 Uncaught ReferenceError: callme is not defined at HTMLInputElement.onchange (UserClaimEditView?userEmail=a@gmail.com:65)