.Net Core Razor引擎 Form複雜模型繫結

FuSh1發表於2020-12-04

複雜模型的繫結

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; }
    }

總結

需要使用特性進行宣告

相關文章