If static, use in your file _Layout.cshtml
:
@Html.Partial("_Menu")
Create a file for this case _Menu.cshtml
If dynamic, use a Action
:
@Html.Action("Menu")
Create for this case a Controller
common and put in it a Action
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 the type IEnumerable<EntradaDoMenu>
(I used this name in my example, but you can create a Model with the name you want):
@model IEnumerable<MeuProjeto.Models.EntradaDoMenu>
<ul>
@foreach (var entrada in Model) {
<li>@Html.ActionLink(entrada.Nome, "Index", entrada.NomeDoController)</li>
}
</ul>
It is really necessary to use the
load()
jQuery to do this or it can be done otherwise?– Leonel Sanches da Silva
Is there any reason why this is not a partial view?
– Miguel Angelo
could be, I’ll read about it. is a static content.
– Dorathoto
I would leave it on Shared, because it can serve for other pages.
– thiago.adriano26
Thiago.adriano26 wants to know which error happened. It would be useful for everyone to help you better.
– Maniero
No mistake, but call a page. html via jquery.load da as 404, anyway, the url is not accessible I think because I don’t have a controller and this inside the views folder
– Dorathoto