I get an error whenever I try to add a new a object to my model I get this error "Object reference not set to an instance of an object." Not sure why as I always create a new object.
I have a Model which consist of:
public class Model
{
public IList<Model1> Something { get; set; }
public IList<Model2> Something1 { get; set; }
}
I also have in my controller:
Model model = new Model();
HttpCookie cookie = Request.Cookies["Login"];
if (cookie != null)
{
int ID = int.Parse(cookie["ID"]);
var DBInfo = db.Details(ID);
foreach (var info in DBInfo)
{
Something1 model1 = new Something1();
model1.ID = ID;
model1.FullName = info.FullName;
model1.CourseCode = info.CourseCode;
model.Something1.Add(model1);
}
The error pops up when I am adding this model1 to model