asp.net mvc - Understanding MVC Models -
in models have:
public class bidmodel { public int id { get; set; } public string firstname{ get; set; } public string lastname{ get; set; } public int price{ get; set; } public string date{ get; set; } }
where or how should define global list list<bidmodel> mylist = new list<bidmodel>;
can add items in 1 controller remove items controller, change content of list wherever want.ok know work database need list of offers becase dont want queries base.
in mode-view-controller, controllers responsibility hand correct model down view, depending on action calling. in mind. don't want create global list bidmodel
.
since using mvc 3 can pass down view quite nicely using dynamic
property viewbag
.
consider this:
public actionresult retreiveallbids() { var bids = bidrepository.getallbids(); viewbag.bids = bids.toarray(); return view(); }
you of course use linq-to-* depending on orm / data storage is. might idea on how pass list
down view.
edit
i miss-read question little bit, still think above valid, depending on how want data accessable , when want dispose it, have 2 options:
- static variable lives during whole life-cycle of web application
- session variable lives current user
and might want these accessable sites, maybe want break functions out , put them in parent class, store bidmodel
list this:
public ienumerable<bidmodel> bids { { return session["bids"] ienumerable<bidmodel>; } set { session["bids"] = value; } }
this way can derive parent class on controllers needs functionality add / list / remove or whatever bidders.
Comments
Post a Comment