且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用MvcSiteMapProvider建立Twitter的引导菜单MVC5

更新时间:2023-02-24 21:18:58

罗云的回答是pretty接近你需要做什么,并且应该促使你沿着正确的方向。该模板的 MyMenu.cshtml 的可以包含你需要输出所需的HTML的任何逻辑。你只需要修改模板,以满足您的要求。请注意,您还可以,如果需要修改默认模板,但你必须要小心选择不的时候问MvcSiteMapProvider的升级过程中,以取代他们,或您的自定义将被覆盖。

Rowan's answer is pretty close to what you need to do, and should have led you down the correct path. The template MyMenu.cshtml can contain any logic you need to output the desired HTML. You simply need to modify the template to meet your requirement. Note that you can also modify the default templates if desired, but you will have to be careful to select "no" when asked to replace them during an upgrade of MvcSiteMapProvider, or your customizations will be overwritten.

@model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel
@using MvcSiteMapProvider.Web.Html.Models

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
        @foreach (var node in Model.Nodes) { 
            <li>@Html.DisplayFor(m => node)</li>
        }
    </ul>
    @Html.Partial("_LoginPartial")
</div>

和再行将产生所需的输出:

And then this line will produce the desired output:

@Html.MvcSiteMap().Menu("MyMenu")