复杂模型的绑定
razor view
<form id='shenlaifusubmit' asp-action="SaveMerchantChannel" method="post">
<div class="form-group">
<label for="pay_memberid">Merchant Id</label>
<input type='text' asp-for="@Model.MerchantPaymentRequest.MerchantId" class="form-control" />
</div>
<div class="form-group">
<label for="pay_memberid">Channel Code</label>
<input id="channel_code" type='text' asp-for="@Model.MerchantPaymentRequest.PayChannelCode" class="form-control" placeholder="请选择Channel" />
</div>
<div class="form-group">
<label>Pay Memberid</label>
<input type='text' asp-for="@Model.MerchantPaymentRequest.PayMemberId" class="form-control" id='pay_memberid' />
</div>
<div class="form-group">
<label for="exampleInputPassword1">PayBankcode</label>
<input type='text' asp-for="@Model.MerchantPaymentRequest.PayBankcode" class="form-control" id='pay_bankcode' />
</div>
<div class="form-group">
<label for="exampleInputPassword1">PayNotifyurl</label>
<input type='text' asp-for="@Model.MerchantPaymentRequest.PayNotifyurl" class="form-control" id='pay_notifyurl' />
</div>
<button class="btn btn-outline-primary" type="submit">提交</button>
</form>
model
[BindProperties(SupportsGet = true)]
public class PaymentChannelModel
{
public List<PaymentChannel> PaymentChannel { get; set; }
[BindProperty]
public MerchantPaymentRequest MerchantPaymentRequest { get; set; }
}
总结
需要使用特性进行声明