asp.net mvc - Adding value to a list of item in a class c# -


below 3 methods,

public class abcorder {     public items items { get; set; } }  public class item {     public string orderrefno { get; set; }     public string sku { get; set; }     public string qty { get; set; }  }      public class items     {         public list<item> item { get; set; }     } 

now want assign below,

abcorder.items.item.add(new item         {             orderrefno = "12345",             sku = "sk8765",             qty = 3          }); 

but getting items null in abcorder.items .please help.

first, don't understand why have items class. why not make abcorder class have list property?

but problem never initialized objects. can't use object if never created it. easiest way in class constructor, this.

public class abcorder {     public abcorder()     {         items = new items();     }     public items items { get; set; } } public class items {     public items()     {         item = new list<item>();     }     public list<item> item { get; set; } } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -