将动态生成的复选框的结果作为字符串传递给控制器

时间:2018-05-15 20:58:56

标签: javascript c# asp.net-mvc

我试图在提交表单时将多个复选框的状态作为字符串传递(当有人检查框时由JS更新),而不是遍历控制器中的每个值。我究竟做错了什么?我试过了:

@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" />
}

错误:

  

UserClaimEditView?userEmail=a@gmail.com:78未捕获的ReferenceError:分配中的左侧无效

选中复选框后出现

错误:

  

UserClaimEditView?userEmail=a@gmail.com:65未捕获的ReferenceError:未定义callme       在HTMLInputElement.onchange(UserClaimEditView?userEmail=a@gmail.com:65)

0 个答案:

没有答案