I have the following viewmodel definition
public class AccessRequestViewModel
{
public Request Request { get; private set; }
public SelectList Buildi
One approach could be to use a private constructor and a static method to return an instance of the object.
public class AccessRequestViewModel
{
private AccessRequesetViewModel() { };
public static GetAccessRequestViewModel (List persons)
{
return new AccessRequestViewModel()
{
Persons = persons,
};
}
public Request Request { get; private set; }
public SelectList Buildings { get; private set; }
public List Persons { get; private set; }
}
By always using the factory to instantiate your ViewModel, you can ensure that there will always be a person.
This probably isn't ideal for what you want, but it would likely work.