Monday, 15 September 2014

c# - How do I initialize a list of objects -



c# - How do I initialize a list of objects -

this controller fetching list of blogpost , stores in listofblogposts:

//bloghome public actionresult bloghome(string pageid, string viewname) { var page = ravensession.load<contentpage>(pageid) bloglistcontentpage; var listofallblogposts = ravensession.query<contentpage>().where(o => o.template.action.equals("singleblogpost")).tolist(); page.singleblogpostscontentpages = listofallblogposts; homecoming view(viewname, page); }

the class containing list:

public class bloglistcontentpage : contentpage { public list<contentpage> singleblogpostscontentpages { get; set; } }

when debugger comes line:

page.singleblogpostscontentpages = listofallblogposts;

i error:

object reference not set instance of object

this mutual error me , not know how solve it..maybe more complicated when you, ib example, utilize inheritance..

the list singleblogpostscontentpages null reason programme show object reference not set instance of object.to avoid alter class bloglistcontentpage :

public class bloglistcontentpage : contentpage { public bloglistcontentpage() { singleblogpostscontentpages = new list<contentpage>(); } public list<contentpage> singleblogpostscontentpages { get; set; } }

c# asp.net-mvc

No comments:

Post a Comment