Please check the controller and model bellow. I am trying to add data to a list property of class CreateProductPage_IniViewData
but problem is when i try to do it normally in controller it says -
System.NullReferenceException: 'Object reference not set to an instance of an object.'
So whats wrong i am doing? Any idea?
Model:
namespace Demo.ViewModels
{
public class CreateProductPage_IniViewData
{
public string StoreUrl { get; set; }
public List<ProductGroupFake> productGroup { get; set; }
}
public class ProductGroupFake
{
public string GroupName { get; set; }
}
}
Controller:
public IActionResult Index()
{
var finalData = new CreateProductPage_IniViewData();
finalData.productGroup.Add(new ProductGroupFake { GroupName = "foo", });
return View();
}