Asp.net中的复选框和表单

时间:2017-07-11 13:03:36

标签: c# asp.net forms model-view-controller checkbox

我有一个控制器,它从数据库加载数据并以表格的形式显示。 我在顶部有一个按钮来执行批量操作。 并在表格中每行前面的复选框执行批量操作。 现在我想用上面的按钮连接这些复选框。我怎样才能做到这一点? 这是我的视图代码?还是连接复选框和按钮的任何其他方式?

@model IEnumerable<WebApplication2.Controllers.Table>
@{
   Layout = null;
}

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>ETL</title>
    <link href="~/Content/css.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />

    @if (ViewBag.Message != null)
    {
        <script type="text/javascript">
                            window.onload = function () {
                            alert("@ViewBag.Message");
                             };
        </script>
    }

</head>

<body>
    <div class="containers">
        <table class="containers" border="0">
            <tbody>
                <tr>
                    <td width="243"><h3 style="padding-bottom:10px;">ETL MANAGEMENT SYSTEM</h3></td>
                    @using (Html.BeginForm("Search", "ETL", FormMethod.Get))
                    {
                        <td width="140">
                            <select class="form-control" style="width:160px; "name="select" id="select">
                                <option name="status">Status</option>
                                <option name="job id">Job Id</option>
                                <option name="Application">Application</option>
                                <option name="Package">Package</option>
                                <option name="Schedulepriority">Schedule Priority</option>
                            </select>
                        </td>
                        <td width="163"><input class="form-control" type="text" name="textfield" id="textfield"></td>
                        <td width="323"><input class="form-control" style="width:100px; " type="submit" name="submit" id="submit" value="Submit"></td>
                    }
                    **<form>
                        <td width="41"><input class="Hold btn" type="button" name="button" id="button" value="Hold"></td>
                        <td width="70"><input class="Complete btn" type="button" name="button2" id="button2" value="Complete"></td>
                        <td width="61"><input class="Pending btn" type="button" name="button3" id="button3" value="Pending"></td>
                        <td width="54"><input class="Cancel btn" type="button" name="button4" id="button4" value="Cancel"></td>
                    </form>
                </tr>**
            </tbody>
        </table>
    </div>
    <div class="containers">
        <table class="containers table table-bordered" border="1">
            <thead>
            <th>&nbsp;</th>
            <th>Job ID</th>
            <th>Application name</th>
            <th>Schedule Name</th>
            <th>Schedule Priority</th>
            <th>Status</th>
            <th>Package Name</th>
            <th>Last Run Time</th>
            <th width="89">Time Since Last Failed</th>
            <th width="101">Actions</th></thead>
            <tbody>
@foreach (var item in Model)
{
                <tr>
                    @{var aff=item.id+"";
                    }
                    <td width="40"><input type="checkbox" name=@aff id=@aff class="form-control"/></td>
                    <td width="84">@Html.DisplayFor(modelItem => item.id)</td>
                    <td width="148">@Html.DisplayFor(modelItem => item.appname)</td>
                    <td width="150">@Html.DisplayFor(modelItem => item.scdname)</td>


                    <td width="113">@Html.DisplayFor(modelItem => item.Priority)</td>
                    <td width="118">@if (item.status.ToLower().Contains("fail"))
                    {
                        using (Html.BeginForm("Data", "ETL", FormMethod.Post))
                        {
                            <input type="hidden" name="id" id="id" value="@item.id" />
                            <input type="submit" id="btnSubmit" value="Failed" class="Cancel btn"/>
                        }
                    }
                    else
                    {
                        @Html.DisplayFor(modelItem => item.status)
                    }</td>
                    <td width="152">@Html.DisplayFor(modelItem => item.pname)</td>
                    <td width="78">@Html.DisplayFor(modelItem => item.lasttime)</td>
                    <td></td>
                    <td>
                        @if (item.status.Equals("Cancelled") || item.status.Equals("Pending") || item.status.Equals("Failed"))
                        {
                            @Html.ActionLink("H","Update", routeValues: new { id = item.id,method="hold"}, htmlAttributes: new { @class = "Hold btn" });
                        }
@if (item.status.Equals("Hold") || item.status.Equals("Failed"))
{
    @Html.ActionLink(linkText: "C", actionName: "Update", routeValues: new { id = item.id, method = "completed" }, htmlAttributes: new { @class = "Complete btn"});
}
@if (item.status.Equals("Cancelled") || item.status.Equals("Completed") || item.status.Equals("Failed") || item.status.Equals("Hold"))
{
    @Html.ActionLink(linkText: "P", actionName: "Update", routeValues: new { id = item.id, method = "pending" }, htmlAttributes: new { @class = "Pending btn "});
}
@if ( item.status.Equals("Launched"))
{
    @Html.ActionLink(linkText: "C", actionName: "Update", routeValues: new { id = item.id, method = "cancel" }, htmlAttributes: new { @class = "Cancel btn" });
}
                    </td>
                </tr>
}
            </tbody>
        </table>
    </div>
</body>
</html>

表格代码:

<form>
                            <td width="41"><input class="Hold btn" type="button" name="button" id="button" value="Hold"></td>
                            <td width="70"><input class="Complete btn" type="button" name="button2" id="button2" value="Complete"></td>
                            <td width="61"><input class="Pending btn" type="button" name="button3" id="button3" value="Pending"></td>
                            <td width="54"><input class="Cancel btn" type="button" name="button4" id="button4" value="Cancel"></td>
                        </form>

这些是复选框,我正在动态生成。

<tr>
                        @{var aff=item.id+"";
                        }
                        <td width="40"><input type="checkbox" name=@aff id=@aff class="form-control"/></td>

In this image there are four buttons at top and checkboxes in front of each row

0 个答案:

没有答案