【问题标题】:Multiple Select for Edit User Wtih CheckBox使用复选框编辑用户的多选
【发布时间】:2017-04-17 09:27:45
【问题描述】:

我有桌子

<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>

在表中,我为选择用户添加了一个复选框以用于更新级别。现在我如何找到学生选择的内容以及如何发送有关他们的信息以采取行动?

【问题讨论】:

  • 不要给负分请指导我
  • 你想在这里做什么? - 你生成复选框(表单控件),甚至没有表单 - 你只有一个链接。你想调用什么控制器方法?除了您生成的无效 html 之外,您所有的复选框都只会发送 truefalse 这将毫无意义。

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


【解决方案1】:

由于您正在遍历学生以呈现复选框,因此我建议使用包含学生 ID 的客户名称创建复选框。

替换

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

类似

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

现在,无论您将这些信息发布到何处,在控制器操作中,表单集合都将包含所有选中的复选框名称,您可以将每个复选框名称解析为“Pass_{StudentId}”,以确定哪些学生被选中。

【讨论】:

  • @Grham 我的问题有两个部分。如何将选定的所有用户发送到操作?
【解决方案2】:

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 2017-11-20
    • 2023-03-18
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    • 2015-12-30
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多