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
Post a Comment