In my project I have a method that creates a menu in the Layout.cshtml layout page, for example, in my control HomeController.cs
is this method, and in ActionResult Index()
I call this method, only I have several other ActionResult
that calls other Views , details page etc .. I have to call this method to create the menu in all ActionResult
? does not have a way every time HomeController
is triggered, regardless of ActionResult
, can I call this method to create the menus? as if it were a Page_Load?
Ex:
In my _Layout.cshtml I have the following:
<ul class="rd-navbar-top-links list-unstyled">
@Html.Raw(ViewBag.Menu)
</ul>
In my "HomeController.cs" I have the following
public ActionResult Index()
{
MontaMenuPrincipal();
return View();
}
public ActionResult OutroMetodo()
{
MontaMenuPrincipal();
return View();
}
public ActionResult OutroMetodo2()
{
MontaMenuPrincipal();
return View();
}
public void MontaMenuPrincipal()
{
ViewBag.Menu = "html com o menu";
}
My question is, do I have to call the MontaMenuPrincipal()
method on all ActionResult
? or do you have some way to call this method for all% of this Controller? without having to repeat it? this would also serve for other methods that would be common for all ActionResult
.
Thank you!