【发布时间】:2020-03-02 19:18:36
【问题描述】:
我有一个 ASP.NET Core MVC Razor 视图,我正在尝试将行 ID 传递给我的控制器。但是,无论我选择哪一行,我都只能传递第一行的行 ID。我正在尝试更新我正在处理的示例应用程序的库存。我需要传入行 ID 号 autoId 和要删除的数量。以下是详细信息。
查看
<div id="InventoryGrid" class="container hiddenGrid">
<div class="row">
<form asp-action="UpdateInventory" method="post" class="container">
<table id="autosTable" class="table table-striped text-center">
<thead class="table-dark">
<tr>
<th>Type</th>
<th>Make</th>
<th>Model</th>
<th>Year</th>
<th>Features</th>
<th>Qty</th>
<th>Sale Price</th>
@*<th>Qty * Price</th>*@
<th>With Markup</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.AutoType)</td>
<td>@Html.DisplayFor(modelItem => item.AutoMake)</td>
<td>@Html.DisplayFor(modelItem => item.AutoModel)</td>
<td>@Html.DisplayFor(modelItem => item.AutoYear)</td>
<td>
@if (item.AutoFeature.Count > 0)
{
@for (int i = 0; i <= item.AutoFeature.Count - 1; i++)
{
<p style="float:left;text-align:center;">
@Html.DisplayFor(modelItem => item.AutoFeature[i].FeatureDescription),
</p>
}
}
</td>
<td>@item.StockLevel</td>
<td class="retailPrice">@item.RetailPrice.ToString("C", culture)</td>
@*<td>@item.EstTotalProfit.ToString("C", culture)</td>*@
<td class="calculatedMarkup"></td>
<td width="200">
<input name="id" type="text" value="@item.AutoId" class="w-25" />
<input name="qty" type="number" min="1" max="@(Html.DisplayFor(modelItem=> item.StockLevel))" class="fomr-control w-25"
/>|
<input type = "submit"
class="btn btn-sm btn-danger"
value="Remove"
/>
</td>
</tr>
}
</tbody>
<tfoot class="table-dark">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Total: @Model.Sum(i => i.RetailPrice).ToString("C", culture)</td>
@*<td>Total: @Model.Sum(i => i.EstTotalProfit).ToString("C", culture)</td>*@
<td class="sumOfProfits"></td>
<td></td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
控制器
[HttpPost]
public IActionResult UpdateInventory(int id, int qty)
{
AutosService autosService = new AutosService(_context);
autosService.UpdateInventory(id, qty);
return RedirectToAction("Index");
}
【问题讨论】:
标签: asp.net-mvc asp.net-core razor asp.net-core-mvc