C# Asp.net中的复选框和表单
我有一个控制器,从数据库加载数据,并以表的形式显示。 我在顶部有一个按钮来执行批量操作。 和表中每行前面的复选框以执行批量操作。 现在我想用上面的按钮连接这些复选框。我该怎么做? 这是我的视图代码?或任何其他连接复选框和按钮的方式C# Asp.net中的复选框和表单,c#,asp.net,forms,model-view-controller,checkbox,C#,Asp.net,Forms,Model View Controller,Checkbox,我有一个控制器,从数据库加载数据,并以表的形式显示。 我在顶部有一个按钮来执行批量操作。 和表中每行前面的复选框以执行批量操作。 现在我想用上面的按钮连接这些复选框。我该怎么做? 这是我的视图代码?或任何其他连接复选框和按钮的方式 @model IEnumerable<WebApplication2.Controllers.Table> @{ Layout = null; } <!doctype html> <html> <head>
@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> </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>
@model IEnumerable
@{
布局=空;
}
ETL
@如果(ViewBag.Message!=null)
{
window.onload=函数(){
警报(“@ViewBag.Message”);
};
}
ETL管理系统
@使用(Html.BeginForm(“Search”、“ETL”、FormMethod.Get))
{
地位
工作Id
应用
包裹
计划优先级
}
**
**
工作ID
应用程序名称
计划名称
计划优先级
地位
包名
上次运行时间
上次失败后的时间
行动
@foreach(模型中的var项目)
{
@{var aff=item.id+“”;
}
@DisplayFor(modeleItem=>item.id)
@DisplayFor(modelItem=>item.appname)
@DisplayFor(modelItem=>item.scdname)
@DisplayFor(modelItem=>item.Priority)
@if(item.status.ToLower()包含(“失败”))
{
使用(Html.BeginForm(“数据”、“ETL”、FormMethod.Post))
{
}
}
其他的
{
@DisplayFor(modelItem=>item.status)
}
@DisplayFor(modelItem=>item.pname)
@DisplayFor(modelItem=>item.lasttime)
@if(item.status.Equals(“取消”)| | item.status.Equals(“待定”)| | item.status.Equals(“失败”))
{
@ActionLink(“H”,“Update”,routeValue:new{id=item.id,method=“hold”},htmlAttributes:new{@class=“hold btn”});
}
@if(item.status.Equals(“保持”)| | item.status.Equals(“失败”))
{
@ActionLink(linkText:“C”,actionName:“Update”,routeValue:new{id=item.id,method=“completed”},htmlAttributes:new{@class=“Complete btn”});
}
@if(item.status.Equals(“取消”)| item.status.Equals(“完成”)| item.status.Equals(“失败”)| item.status.Equals(“保留”))
{
@ActionLink(linkText:“P”,actionName:“Update”,routeValue:new{id=item.id,method=“pending”},htmlAttributes:new{@class=“pending btn”});
}
@if(item.status.Equals(“已启动”))
{
@ActionLink(linkText:“C”,actionName:“Update”,routeValue:new{id=item.id,method=“cancel”},htmlAttributes:new{@class=“cancel btn”});
}
}
表格编号:
<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>
@{var aff=item.id+“”;
}
您想在回发时(在C#controller中)还是在Javascript中执行此操作?无论哪种方式,您都需要找到所有选中的复选框,然后以某种方式使用该列表。您还没有弄清楚这些按钮在您的情况下实际会做什么——它们是在页面上执行其他操作,还是将数据提交到API,或者重定向到另一个页面?确切的用例会影响您解决问题的确切方式。它们只会重定向到C#controller。并对检查的行进行一些更新。使用gridview asp.net控件会更好