【发布时间】:2021-01-04 15:18:56
【问题描述】:
我有这个 Blazor 应用程序,其中有以下模型类:
public class Purchase
{
public Payment payment { get; set; }
}
public class Payment
{
public string operation { get; set; }
public string intent { get; set; }
public string currency { get; set; }
public Price[] prices { get; set; }
public string description { get; set; }
public string userAgent { get; set; }
public string language { get; set; }
public Urls urls { get; set; }
public Payeeinfo payeeInfo { get; set; }
public Cardholder cardholder { get; set; }
public Riskindicator riskIndicator { get; set; }
}
public class Urls
{
public string completeUrl { get; set; }
public string cancelUrl { get; set; }
public string callbackUrl { get; set; }
public string logoUrl { get; set; }
public string termsOfServiceUrl { get; set; }
}
public class Payeeinfo
{
public string payeeId { get; set; }
public string payeeReference { get; set; }
public string payeeName { get; set; }
public string productCategory { get; set; }
public string orderReference { get; set; }
public string subsite { get; set; }
}
public class Cardholder
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string msisdn { get; set; }
public string homePhoneNumber { get; set; }
public string workPhoneNumber { get; set; }
public Shippingaddress shippingAddress { get; set; }
}
public class Shippingaddress
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string msisdn { get; set; }
public string streetAddress { get; set; }
public string coAddress { get; set; }
public string city { get; set; }
public string zipCode { get; set; }
public string countryCode { get; set; }
}
public class Riskindicator
{
public string deliveryEmailAddress { get; set; }
public string deliveryTimeFrameIndicator { get; set; }
public string preOrderDate { get; set; }
public string preOrderPurchaseIndicator { get; set; }
public string shipIndicator { get; set; }
public bool giftCardPurchase { get; set; }
public string reOrderPurchaseIndicator { get; set; }
public Pickupaddress pickUpAddress { get; set; }
}
public class Pickupaddress
{
public string name { get; set; }
public string streetAddress { get; set; }
public string coAddress { get; set; }
public string city { get; set; }
public string zipCode { get; set; }
public string countryCode { get; set; }
}
public class Price
{
public string type { get; set; }
public int amount { get; set; }
public int vatAmount { get; set; }
}
我尝试在 razor 组件中这样实现:
@page "/testpay"
@using Kanal10.UI.Models.Payex
<!-- Content -->
<div class="donate">
<div class="donate-pay wrapper">
<EditForm Model="purchase" OnValidSubmit="SavePurchase">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="form-group">
<label>Firstname</label>
<InputText id="firstName" @bind-value="purchase.payment.cardholder.firstName" class="form-control"></InputText>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</EditForm>
</div>
</div>
@code {
private Purchase purchase = new Purchase();
private void SavePurchase()
{
}
}
但是当我渲染页面时,我收到错误消息,我不太明白为什么。
NullReferenceException:对象引用未设置为对象的实例。 Kanal10.UI.Pages.PayTest.b__0_1(RenderTreeBuilder __builder2)
如果有人有答案,我将不胜感激。
彼得
【问题讨论】:
标签: asp.net-core razor blazor