プロファイルを保存しようとすると、オブジェクト参照がオブジェクトのインスタンスに設定されていないというエラーが表示されます。
「if」ステートメント if (this.Profile.ProfileDetail != null ) を追加しようとしましたが、それでも同じエラーが発生しました。
これは私のコードです:
private void SaveProfile()
{
this.Profile.ProfileDetail.FullName = txtfname.Text;
this.Profile.ProfileDetail.IdentityCardNo = txtcardno.Text;
this.Profile.ProfileDetail.IdentityCardColour = ddlcardcolor.SelectedValue;
this.Profile.ProfileDetail.IdentityCardExpiryDate = DateTime.Parse(txtcardexp.Text);
this.Profile.ProfileDetail.Race = ddlrace.SelectedValue;
this.Profile.ProfileDetail.Religion = ddlreligion.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.Address1 = txtaddress1.Text;
this.Profile.ProfileDetail.ContactInformation.Address2 = txtaddress2.Text;
this.Profile.ProfileDetail.ContactInformation.Address3 = txtaddress3.Text;
this.Profile.ProfileDetail.ContactInformation.Postcode = txtpostcode.Text;
this.Profile.ProfileDetail.ContactInformation.District = ddldistrict.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.OfficePhone = txtphoneoffice.Text;
this.Profile.ProfileDetail.ContactInformation.HomePhone = txtphonehome.Text;
this.Profile.ProfileDetail.ContactInformation.MobilePhone = txtphonecell.Text;
this.Profile.ProfileDetail.ContactInformation.Email = txtemail.Text;
//this.Profile.ProfileDetail.FirstName = txtFirstName.Text;
//this.Profile.ProfileDetail.LastName = txtLastName.Text;
//this.Profile.ProfileDetail.IdentityCardNo = txtICNo.Text;
//this.Profile.ProfileDetail.DateOfBirth = DateTime.Parse(txtDateOfBirth.Text);
//this.Profile.ProfileDetail.Gender = (Gender)Enum.Parse(typeof(Gender), ddlGender.SelectedValue, true);
//this.Profile.Preferences.TimeZone = ddlTimeZones.SelectedValue;
//this.Profile.Preferences.Culture = ddlCultures.SelectedValue;
this.Profile.Save();
this.ResetElements();
}