从 ASP.NET Core 5 MVC 中的复选框中选中的项目获取 ID
Get ID from item which is checked from checkbox in ASP.NET Core 5 MVC
我需要帮助!
我有一个 ASP.NET Core 5 MVC Web 应用程序。我有一个包含 .mdf 数据库中项目的列表,并希望在每个项目行的末尾有一个复选框。当我在这个视图的控制器中时,我想要检查项目的 ID。可以检查不止一个。但我不知道该怎么做。
下面是我的代码中的一些片段:
Index.cshtml
<form asp-action="Send">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Bez)
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Bez)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
<td>
@Html.CheckBox("Finalized", false)
</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="Send" class="btn btn-primary" />
<br /><br />
<p>Achtung! Beim Senden an einem Freitag wird der Dienstplan automatisch für den darauffolgenden Montag eingeteilt.</p>
</form>
有人可以帮助我吗?我只希望 id 在我的控制器中的列表中,已检查。
您似乎想post 选定的 ID 到后端。这是您可以关注的工作演示:
@Html.CheckBox("Finalized", false,new { @value=item.Id})
控制器:
[HttpPost]
//if the type of item.Id is int, it will receive int array in backend
public IActionResult Send(int[] Finalized)
{
//do your stuff...
}
我需要帮助! 我有一个 ASP.NET Core 5 MVC Web 应用程序。我有一个包含 .mdf 数据库中项目的列表,并希望在每个项目行的末尾有一个复选框。当我在这个视图的控制器中时,我想要检查项目的 ID。可以检查不止一个。但我不知道该怎么做。 下面是我的代码中的一些片段:
Index.cshtml
<form asp-action="Send">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Bez)
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Bez)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
<td>
@Html.CheckBox("Finalized", false)
</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="Send" class="btn btn-primary" />
<br /><br />
<p>Achtung! Beim Senden an einem Freitag wird der Dienstplan automatisch für den darauffolgenden Montag eingeteilt.</p>
</form>
有人可以帮助我吗?我只希望 id 在我的控制器中的列表中,已检查。
您似乎想post 选定的 ID 到后端。这是您可以关注的工作演示:
@Html.CheckBox("Finalized", false,new { @value=item.Id})
控制器:
[HttpPost]
//if the type of item.Id is int, it will receive int array in backend
public IActionResult Send(int[] Finalized)
{
//do your stuff...
}