如何在mvc中设置选中的第一个复选框

How to set first checkbox checked in mvc

这里我想设置第一个复选框checked.I我不明白怎么做,因为它在 viewbag 中。

<div class="form-group">

@Html.LabelFor(m => m.RBO_Location, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
        @foreach (var item in (SelectList)ViewBag.Branches)
      {  
      <div>
      <input type="checkbox" name="selectedBranches"          value="@item.Value" class="checkbox-inline" />
       @Html.Label(item.Text, new { @class = "control-label" })
           </div>
      }
  </div>
  </div>

How to set first checkbox checked in mvc

这可以在 Document.Ready 处使用 Jquery 来完成。

$("input[type=checkbox][name=selectedBranches]:first").attr('checked','checked');