url in MVC project of an .html

0

I would like to create a .html that will serve to be the _Layout.cshtml menu, I will call it through $("#IDMenu").load('menu_Home.html');

My question, what better place to leave it? I can leave it in the folder

/Shared/ ?
_Layout.cshtml
menu_home.html
menu_admin.html

and in that masterpage _Layout.cshtml, what would it call it?

/views/Shared/menu_home.html 'não funcionou'
Shared/menu_home.html 'não funcionou' 
    
asked by anonymous 13.05.2014 / 20:33

1 answer

2

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>
    
13.05.2014 / 21:18