如何将以下列表添加PosttypeMetas
到我的视图模型中?
static void Main(string[] args)
{
List<PosttypeMetas> a = new List<PosttypeMetas>();
a.Add(new PosttypeMetas { Metatexts = "1", Selects = "mazhar" });
a.Add(new PosttypeMetas { Metatexts = "2", Selects = "mazhar1" });
a.Add(new PosttypeMetas { Metatexts = "3", Selects = "mazhar2" });
a.Add(new PosttypeMetas { Metatexts = "4", Selects = "mazhar3" });
a.Add(new PosttypeMetas { Metatexts = "5", Selects = "mazhar4" });
PosttypeVM abc = new PosttypeVM();
foreach (var listf in a)
{
PosttypeMetas abcc = new PosttypeMetas();
abcc.Metatexts = listf.Metatexts;
abcc.Selects = listf.Selects;
abc.posttypemeta.Add(abcc); // NullReferenceException
}
Console.Read();
}
public class PosttypeVM
{
public string module { get; set; }
public string IsModule { get; set; }
public string parent { get; set; }
public string OrgorSys { get; set; }
public string ModuleName { get; set; }
public List<PosttypeMetas> posttypemeta { get; set; }
}
public class PosttypeMetas
{
public string Metatexts { get; set; }
public string Selects { get; set; }
}