I am trying to pull from the database a saved Title. I want it to load every time without using the view to call it. So I want a variable to be pulled when I call it from the Layout. How can I do this?
In Layout Example:
@ViewBag.ShowTitle
This would show to every single page that renders the layout. I’m not sure how I would call the field from the database to the screen without a controller.
Just call a
PartialViewin your_Layout.cshtmlpage.but you do need a
Controllerto interact with the database and to assign theTitlevalue to theViewBag.PartialView
You can also do as described in the following link where you define a
ViewModel, aControllerand calls@Html.Actioninside_Layout.cshtml:ASP.NET MVC 3 _Layout.cshtml Controller