asp.net - Best and proper way to use Entity Framework in _Layout -
i have standard asp.net template, has _layout menu generated. have multiple data contexts representing different databases throughout application , works fine.
i want add count bootstrap badge next 1 of items in _layout. need pass in db.ticketdal.count(). best way directly layout. did try passing data in viewbag entry home controller when go different controllers doesn't display. modify each controller seems wrong way it. suspect overthinking advice appreciated.
you must create basecontroller. there can var ticketcount = db.ticketdal.count(); or list<menuitems> let's , other controllers must inherit basecontroller in of them , in of methods have same instance of list<menuitems> or ticketcount
or can create helper class.
public static class baseknowledgehelper { public static int getticketcount() { return db.ticketdal.count(); } } and call everywhere: @baseknowledgehelper.getticketcount()
Comments
Post a Comment