0
In my project I have a method that creates a menu on the layout page "_Layout.cshtml", for example, in my control HomeController.cs
this method remains, and in ActionResult Index()
I call this method, only I have several other ActionResult
who calls other Views, details page etc.. I have to call this method to create the menu in all ActionResult
? there’s a way every time HomeController
is triggered, regardless of the 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, I have to call the method MontaMenuPrincipal()
in all ActionResult
? or has some way of calling this method for all ActionResult
of that Controller? without having to repeat it? it would also serve other methods that would be common for all ActionResult
.
Thank you!
Felipe, this part I understood well, I edited my question to see if it is clearer, and thank you for the help!
– Dark Ducke