I need help understand why I getting a null object reference here:
I have 2 models:
public class loadViewModel
{
public importacaoConfig importacaoConfig { get; set; }
}
public class importacaoConfig
{
public List<DocTypeModel> tipo { get; set; }
}
Im my controler I am passing a List to the model:
gedaiapp.Models.loadViewModel model = new gedaiapp.Models.loadViewModel();
model.importacaoConfig.tipo = obj; -> Here obj is of type List<DocTypeModel>
This gives me:
System.NullReferenceException: Object reference not set to an instance of an object.
I have checked and the obj list has 3 elements.
Which reference is null here? I don´t get it.
The problem is this:
model.importacaoConfig.tipoYou haven’t instantiated
importacaoConfig, so it’s null (hence why you get the exception on that line.Add this line to instantiate it (between your two existing lines):
So your controller would be: