If it is static, use in your file _Layout.cshtml
:
@Html.Partial("_Menu")
Create a _Menu.cshtml
If dynamic, use Action
:
@Html.Action("Menu")
Create a Controller
common% in this case and put a Action
in it that populates this menu:
namespace MeuProjeto.Controllers
{
public class CommonController : Controller
{
private MeuProjetoContext context = new MeuProjetoContext();
[ChildActionOnly]
public ActionResult Menu()
{
var menu = context.EntradasDoMenu.ToList();
return PartialView(menu);
}
}
}
Also create a View called Shared\Menu.cshtml
that receives a Model of type IEnumerable<EntradaDoMenu>
(I used this name in my example, but you can create a Model with whatever name you want):
@model IEnumerable<MeuProjeto.Models.EntradaDoMenu>
<ul>
@foreach (var entrada in Model) {
<li>@Html.ActionLink(entrada.Nome, "Index", entrada.NomeDoController)</li>
}
</ul>