I have fb,twitter and youtube urls in DB, and about 30 other application level variable.
currently I am querying it in each action bcz in template I have social links in footer, if missed that will throw error.
ViewBag.Contents = db.Contents.Where(s => s.status == 1).OrderBy(s => s.group).ThenBy(s => s.sort).ToList();
I want above line to be executed for all action somewhere globaly. Googled for it, many people are suggesting to put in session but i think this should not go in session variables as its size may go long.
All my controllers are inherited from Controller
as
public class HomeController : Controller{}
please help.
UPDATE I have created constructor in home controller as below
public HomeController()
{
if (ViewBag.Contents == null)
{
ViewBag.Contents = db.Contents.Where(s => s.status == 1).OrderBy(s => s.sort).ToList();
}
}
this reduced calling it in each action, but still I have to type the same in all controllers, Is this ok or not? and how can we write this globally for all controllers