使用CheckBox

时间:2016-12-02 12:54:01

标签: c# asp.net asp.net-mvc asp.net-mvc-4 c#-4.0

我有桌子

<table class="table table-hover">
        <thead>
        <tr>
            <th>userid</th>
            <th>image</th>
            <th>name</th>
            <th>family</th>
            <th>level</th>
            <th>fild</th>
            <th>operation</th>
            <th>up to next level</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var item in StudentFunc.ShowAllStudents(Model.Class))
        {
            <tr>
                <td>@item.studentid</td>
                <td>
                    <img src="~/Image/StudentImage/@item.studntimage" width="60" height="60"/>
                </td>
                <td>@item.studentname</td>
                <td>@item.studentfamily</td>
                <td>@item.studentpayename</td>
                <td>@item.studentreshtename</td>
                <td>
                    <a onclick="Edit()" class="btn btn-primary click" href="@Url.Action("InsertScore", "Home", new {payeid = @item.PayeID, reshteid = @item.ReshteID, studentiD = @item.studentid, MostamarID = @StudentFunc.ShowStudents(item.studentid).MostamarID})"><span class="glyphicon glyphicon-pencil"><span style="font-family: 'B Titr'; margin-right: 10px;">ثبت نمره</span></span></a>
                    <a class="btn btn-default" href="@Url.Action("ListofScore", "Home", new {studentid = @item.studentid})"><span class="glyphicon glyphicon-list"><span style="font-family: 'B Titr'; margin-right: 10px;">لیست نمرات</span></span></a>
                    <a class="btn btn-default" href="@Url.Action("AddAbsent", "Home", new {studentid = @item.studentid})"><span class="glyphicon glyphicon-list"><span style="font-family: 'B Titr'; margin-right: 10px;"> ثبت غیبت</span></span></a>

                </td>
                <td>@Html.CheckBox("Pass", false)</td>
            </tr>
        }
        </tbody>
    </table>
表中的

我为select user选择了一个更新级别的复选框。现在,我如何找到学生选择的内容以及如何发送有关他们的信息?

2 个答案:

答案 0 :(得分:0)

一种选择是将代码放在表单中并替换

@Html.CheckBox("Pass", false) 
//with something like 
@Html.CheckBoxFor(item => item.Pass) 

并提交表格(您应该可以这样做)。

或者您可以在javascript中保留包含学生ID的列表(在检查/取消选中时添加/删除学生ID)并使用ajax调用将该列表发送到服务器。

这些只是一些提示,你必须自己尝试编写这段代码。

答案 1 :(得分:0)

由于您正在通过学​​生迭代渲染复选框,我建议使用包含学生ID的客户名称创建复选框。

替换

<td>@Html.CheckBox("Pass", false)</td>

类似

<td>@Html.CheckBox("Pass_" + item.studentid)</td>

现在,在控制器操作中,无论您将这些发布到哪个位置,表单集合都将包含所有选中的复选框名称,您可以解析每个复选框名称,以便&#34; Pass_{StudentId}&#34;找出哪些学生被选中。