我正在运行.Net-Core 2,我想在用户提交表单时发回完整的模型。目前,我正在为所有属性手动添加隐藏字段。
@for (var index = 0; index < Model.PaymentOptions.Count; index++)
{
var paymentOption = Model.PaymentOptions[index];
<input type="hidden" name="@($"PaymentOptions[{index}].Sender.AccountId")"
value="@paymentOption.Sender.AccountId" />
<input type="hidden" name="@($"PaymentOptions[{index}].Sender.AccountName")"
value="@paymentOption.Sender.AccountName" />
<input type="hidden" name="@($"PaymentOptions[{index}].Sender.Currency")"
value="@paymentOption.Sender.Currency" />
<input type="hidden" name="@($"PaymentOptions[{index}].Sender.Balance")"
value="@paymentOption.Sender.Balance" />
<input type="hidden" name="@($"PaymentOptions[{index}].Sender.Address")"
value="@paymentOption.Sender.Address" />
<input type="hidden" name="@($"PaymentOptions[{index}].Receiver.AccountId")"
value="@paymentOption.Receiver.AccountId" />
<input type="hidden" name="@($"PaymentOptions[{index}].Receiver.AccountName")"
value="@paymentOption.Receiver.AccountName" />
<input type="hidden" name="@($"PaymentOptions[{index}].Receiver.Currency")"
value="@paymentOption.Receiver.Currency" />
<input type="hidden" name="@($"PaymentOptions[{index}].Receiver.Balance")"
value="@paymentOption.Receiver.Balance" />
<input type="hidden" name="@($"PaymentOptions[{index}].Receiver.Address")"
value="@paymentOption.Receiver.Address" />
}
此代码非常多余。我不想在服务器上修改模型,因为我的大部分数据都是从第三方API获取的。
有没有一种方法可以自动备份模型中具有隐藏字段的所有属性?