首页 > 解决方案 > 如何从存在多个局部视图且每个局部视图没有提交按钮的视图中将值设置为 db?

问题描述

我的视图页面有多个部分视图。每个局部视图都是一个具有唯一输入值的表,每个视图都采用具有不同 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>

这是我的视图的块方案: 在此处输入图像描述

标签: javascriptc#asp.net-core-mvc

解决方案


推荐阅读