Initialized inherited variable is blank

Viewed 22

I am new to MVC and am still feeling my way around but I'm not sure what I did wrong here. I've tried numerous different ways to test why the variable values are not held when in a different view model.

I inherited the BaseViewModel in the subclass and when debugging the value is set correctly when accessed by the EnrollmentViewModel, but once it enters the LicenseViewModel it is blank. I know I'm missing something but I'm not sure what. Is it because I need to add a call within the LicenseViewModel constructor to make the call to the Assign function? I believe I tried this already but it did not work. Other than doing that, I wasn't sure of what else I could do.

public class BaseViewModel
{
   public bool securitydetails {get; set;}
}

public class UserManager
{
    public BaseViewModel Assign(BaseViewModel request)
    (
        //set securitydetails
    )
)

public class EnrollmentViewModel : BaseViewModel
{
    public OfficialLicenseViewModel LicenseViewModel{get; set;}
    
    public class OfficialLicenseViewModel : BaseViewModel
    {
    }

    public EnrollmentViewModel()
    {
        LicenseViewModel = new OfficialLicenseViewModel();
    )
}

EnrollmentManager
{
    public EnrollmentViewModel GetVM(.....)
    {
        UserManager.Assign(...)
    }
}

EnrollmentController
{
    public virtual ActionResult GetEnrollmentViewModel
    {
        return PartialView(...EnrollmentViewModel)
    }
}

**_EnrollmentViewModel.cshtml** 
    //model.securitydetails is initilized as expected

          return PartialView(...LicenseViewModel...)

**_LicenseViewModel.cshtml** 
    //model.securitydetails is empty
0 Answers
Related