我有包含多个部分视图的视图页面。每个局部视图都是一个具有唯一输入值的表,每个视图都采用具有不同id的相同模型。而且我还有一个提交按钮用于所有这些表。我该如何检索数据? 这是我的局部视图,可以多次渲染。
@{ var i = 1;}
@foreach (var spread in Model.Spreads)
{
var cashSpreadBuy = "cashSpreadBuy" + spread.Curr.ShortName + spread.ID;
var cashBuyCurrent = "cashBuyCurrent" + spread.Curr.ShortName + spread.ID;
var cashSpreadSell = "cashSpreadSell" + spread.Curr.ShortName + spread.ID;
var cashSellCurrent = "cashSellCurrent" + spread.Curr.ShortName + spread.ID;
var nonCashSpreadBuy = "nonCashSpreadBuy" + spread.Curr.ShortName + spread.ID;
var nonCashBuyCurrent = "nonCashBuyCurrent" + spread.Curr.ShortName + spread.ID;
var nonCashSpreadSell = "nonCashSpreadSell" + spread.Curr.ShortName + spread.ID;
var nonCashSellCurrent = "nonCashSellCurrent" + spread.Curr.ShortName + spread.ID;
spread.ID = i;
i++;
<tr>
<td> @spread.Curr.ShortName </td>
<td>
<input asp-for="@spread.CashSpreadBuy" class="form-control" id="@(cashSpreadBuy)" type="number" step="0.01"
onkeyup="Calculate('rateCashBuyCurrent', '@(cashSpreadBuy)', '@(cashBuyCurrent)', false, '@spread.Curr.ShortName')"
onmouseup="Calculate('rateCashBuyCurrent', '@(cashSpreadBuy)', '@(cashBuyCurrent)', false, '@spread.Curr.ShortName')" />
</td>
<td id=@(cashBuyCurrent)> @spread.CashBuyCurrent </td>
<td>
<input asp-for="@spread.CashSpreadSell" class="form-control" id="@(cashSpreadSell)" type="number" step="0.01"
onmouseup="Calculate('rateCashSellCurrent', '@(cashSpreadSell)', '@(cashSellCurrent)', false, '@spread.Curr.ShortName')"
onkeyup="Calculate('rateCashSellCurrent', '@(cashSpreadSell)', '@(cashSellCurrent)', false, '@spread.Curr.ShortName')" />
</td>
<td id=@(cashSellCurrent)> @spread.CashSellCurrent </td>
<td>
<input asp-for="@spread.NonCashSpreadBuy" class="form-control" id="@(nonCashSpreadBuy)" type="number" step="0.01"
onmouseup="Calculate('rateNonCashBuyCurrent', '@(nonCashSpreadBuy)', '@(nonCashBuyCurrent)', false, '@spread.Curr.ShortName')"
onkeyup="Calculate('rateNonCashBuyCurrent', '@(nonCashSpreadBuy)', '@(nonCashBuyCurrent)', false, '@spread.Curr.ShortName')" />
</td>
<td id=@(nonCashBuyCurrent)> @spread.NonCashBuyCurrent </td>
<td>
<input asp-for="@spread.NonCashSpreadSell" class="form-control" id="@(nonCashSpreadSell)" type="number" step="0.01"
onmouseup="Calculate('rateNonCashSellCurrent', '@(nonCashSpreadSell)', '@(nonCashSellCurrent)', false, '@spread.Curr.ShortName')"
onkeyup="Calculate('rateNonCashSellCurrent', '@(nonCashSpreadSell)', '@(nonCashSellCurrent)', false, '@spread.Curr.ShortName')" />
</td>
<td id=@(nonCashSellCurrent)> @spread.NonCashSellCurrent </td>
</tr>
}
</tbody>
</table>
这是我的观点的块方案: enter image description here