MVC 3 多选

前台:

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <table>
        <tr>
            <th>
                选择
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    <input type="checkbox" id="checkboxRole" name="checkboxRole"  value="@item.Value" />
                </td>
                <td>
                    @item.Name
</td> </tr> } </table> <p> <input type="submit" value="Save" /> </p> }

 

 后台:

 

if(collection.GetValues("checkboxRole")!=null)
             {
                 string strRoles = collection.GetValue("checkboxRole").AttemptedValue;
                 string[] lstRoles = strRoles.Split(',');   //获取到所选内容
                 //..........你的代码..........
             }

 

posted on 2012-06-07 16:22  CosmoKey  阅读(645)  评论(0编辑  收藏  举报

导航