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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -