I have the following viewmodel with a constructor:
public class ActivitiesReportViewModel
{
public ActivitiesReportViewModel()
{
List<ActivityType> ActivityTypeList = new List<ActivityType>();
List<Activity> ActivityList = new List<Activity>();
List<Client> ClientList = new List<Client>();
List<List<ActivityCounter>> ActivityCounterList = new List<List<ActivityCounter>>();
}
[DisplayName("Responsável")]
public string UserName { get; set; }
[DisplayName("Data Inicial")]
[Required]
public DateTime DateFrom { get; set; }
[DisplayName("Data Final")]
[Required]
public DateTime DateTo { get; set; }
[DisplayName("Tipos de Atividade")]
public virtual List<ActivityType> ActivityTypeList { get; set; }
[DisplayName("Atividades")]
public virtual List<Activity> ActivityList { get; set; }
[DisplayName("Clientes")]
public virtual List<Client> ClientList { get; set; }
public List<List<ActivityCounter>> ActivityCounterList { get; set; }
}
And my ActionResult:
public ActionResult ActivityReport()
{
var model = new ActivitiesReportViewModel();
return View(model);
}
But after initializing model, all lists are null as bellow:
I debugged the execution of the code and seems like the constructor is being correctly called, I just can't understand why all lists are still null after this.
I'm new to C#, so maybe I'm just missing something basic here and will be very grateful for any help you could provide.
Thank you in advance.
Ps: the problem with this situation is that I get a null refference exception because my lists are null when used in my view.