gpt4 book ai didi

c# - 我怎样才能有一个包含单元格的表作为输入来更新 NET 5 MVC 中的数据

转载 作者:行者123 更新时间:2023-12-05 05:57:04 25 4
gpt4 key购买 nike

我有一个具有这种结构的表的 View :

<form asp-action="Index">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<table class="table table-hover table-responsive-sm display">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Descripcion)
</th>
<th>
@Html.DisplayNameFor(model => model.Activa)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<input value="@Html.DisplayFor(modelitem => item.AreaClave)"/>
</td>
<td>
<input id="desc" name="desc" value="@Html.DisplayFor(modelItem => item.Descripcion)" />
</td>
<td>
<input value="@Html.DisplayFor(modelItem => item.Activa)" />
</td>
<td>
<div class="form-group">
<button asp-route-id="@item.AreaClave" type="submit" name="action">Update</button>
</div>
</td>
</tr>
}
</tbody>
</table>

我想要多行打开“item.Descripcion”输入,这是因为我希望能够通过行 ID 单独更新每一行。这种方法对第一行同样有效,但对接下来的行不起作用。我认为这是因为名称标签重复并且只考虑第一个。有没有办法让我的表的每一行都有一个更新输入?

最佳答案

你可以尝试生成<form><table>对于如下每个项目:

@model IEnumerable<Test>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<table class="table table-hover table-responsive-sm display">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Descripcion)
</th>
<th>
@Html.DisplayNameFor(model => model.Activa)
</th>
<th></th>
</tr>
</thead>
</table>
@foreach (var item in Model)
{
<form asp-action="Index">
<table class="table table-hover table-responsive-sm display">
<tbody>
<tr>
<td>
<input value="@Html.DisplayFor(modelitem => item.AreaClave)" />
</td>
<td>
<input id="desc" name="desc" value="@Html.DisplayFor(modelItem => item.Descripcion)" />
</td>
<td>
<input value="@Html.DisplayFor(modelItem => item.Activa)" />
</td>
<td>
<div class="form-group">
<button asp-route-id="@item.AreaClave" type="submit" name="action">Update</button>
</div>
</td>
</tr>
</tbody>
</table>
</form>
}

后端代码:

[HttpPost]
public IActionResult Index(string id,string desc)
{
//do your stufff...
}

关于c# - 我怎样才能有一个包含单元格的表作为输入来更新 NET 5 MVC 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68926965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com