我该如何制作菜单? [英] how can i make a menu?

查看:91
本文介绍了我该如何制作菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在mvc视图中制作菜单。我不知道我该怎么做!!有没有人帮我?

我是初学者....

I want to make menu in mvc view.I don't know how can i do this!!Is there anyone to help me?
I am a beginner....

推荐答案

https://www.google.com/搜索?q = menu + in + mvc [ ^ ]。


MVC应用程序的菜单在文件Views文件夹中定义 - >共享文件夹 - > _Layout.cshtml文件



如果您打开文件并浏览它,您将看到诸如



The menu for the MVC application is defined in the file "Views" folder->"Shared" folder ->_Layout.cshtml file

If you open the file and browse it through you will see entries like

<nav>
    <ul id="menu">
        <li>@Html.ActionLink("Home", "Index", "Home")</li>
        <li>@Html.ActionLink("About", "About", "Home")</li>
        <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
    </ul>
</nav>







这是你定义新菜单的地方,请谷歌,如果你需要知道




This is where you will defined your new menu and please google it, if you needs to know the parameter for

@Html.ActionLink







希望这个帮助




Hope this helps


创建一个具有菜单和子菜单重新显示的逻辑的实体类,作为模型工作。



create an entity class with menu and sub menu relalted logic, that work as model.

public int Id { get; set; }
public string Name { get; set; }
public string Action { get; set; }
public string Controller { get; set; }
public List<Menu> SubMenu { get; set; }





在控制器中你必须在你的基类中添加一个方法。这个基类应该由你的每个页面来表示。申请。





In controller you have to add one method in your base class.This base class should be exectued by each and every pages of your application.

public ActionResult MenuBar()
        {
            var menuItems = from t in dbContext.GetMenuItem(Session["LoggedInID"])
                            select t;

            return PartialView("Menubar", menuItems);

        }





创建一个由每个控制器继承的基页。



然后最后创建一个需要放入Layout.cshtml页面的视图。



@ Html.Action(菜单栏);



和In View你必须为你的模型设置循环,并根据你的设计创建相关的html加载你的菜单。



create one basePage that inherited by every controller.

and then finally create one view that need to put in Layout.cshtml page.

@Html.Action("Menubar");

and In View you have to put loop for your model and will create relavant html to load your menu based on your desing.


这篇关于我该如何制作菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆