c# - Why is my nested CustomerViewModel null? -
I managed to register an applicant, and now I would like to request an HTTP GET that is currently logged in The account displays the details in an explanation.
However, when I run the application and go to the "MyPage" view, I get an exception that the Nested Client View Model is a null. I have no idea at all why this is for some reason.
This is the action taken in the Home Controller C.
Public actions MyPages () {string userId = User Identity.GetUserId (); Var current user = _userRepository.GetById (userId); Var customer = _customerRepository.GetById (currentUser.Customer.Id); Var userview model = new userview model (); UserViewModel.Id = currentUser.Id; UserViewModel.UserName = currentUser.UserName; // This is where the exception is generated. Apperantly Customer ViewModel is the userViewModel.CustomerViewModel.Id = customer.Id; UserViewModel.CustomerViewModel.FirstName = customer.FirstName; UserViewModel.CustomerViewModel.LastName = customer.LastName; UserViewModel.CustomerViewModel.Email = Customer.mail; See refresh (user viewmodel); } This is UserViewModel
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.Security; Using Microsoft.AspNet.Identity.EntityFramework; Namespot GUI.Models {Public class UserViewModel {public virtual string id {get; Set; } Public Virtual String Username {get; Set; } Public Virtual String PasswordHash {get; Set; } Public Virtual String Security Stamp {get; Set; } Public virtual iconging & lt; Identity Usherol & gt; Roles {receive; Set; } Public Virtual Icons & lt; IdentityUserClaim & gt; Claim (get); Set; } Public virtual iconenging & lt; IdentityUserLogin & gt; Login {received; Set; } Receive Public Customer View Model Customer View Model { Set; }}} And this is Customer View Model:
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.ComponentModel.DataAnnotations; Using the Classroom Library. Namespot GUI.Models {Public Class CustomerViewModel {Public Guide ID {get; Set; } [Required] [display (name = "first name")] public string first name {received; Set; } [Required] [display (name = "last name")] public string LastName {get; Set; } [Display (name = "email address")] [Required (error message = "email address is required")] [email address (error message = "invalid email address")] public string email {get; Set; } Public List & amp; View invoiceModel & gt; Invoice view models {receive; Set; } Public listing & lt; Addressviewmodal & gt; {Get AdressViewModels; Set; } Public Address ViewModel AdressViewModel {Receive; Set; } Public Virtual Icons & lt; Invoices & gt; Invoice {receive; Set; } Public virtual iconging & lt; Adress & gt; Address {receipt; Set; }}} What's the problem here?
I'm missing something in your code, but this is a new customer view model does not look like userViewModel.CustomerViewModel for immediate. You can save some problems and create a new example for UserViewModel : public class UserViewModel {public user viewmodel () {CustomerViewModel = new CustomerViewModel (); } Receive Public Customer View Model Customer View Model { Set; }}
Comments
Post a Comment