MvcSiteMapProvider菜单,在Asp.Net Mvc 5的Controller类中具有过滤器属性 [英] MvcSiteMapProvider Menu with Filter Attributes in the Controller Class in Asp.Net Mvc 5

查看:99
本文介绍了MvcSiteMapProvider菜单,在Asp.Net Mvc 5的Controller类中具有过滤器属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下库: https://github.com/maartenba/MvcSiteMapProvider

我想要一个这样的菜单结构:

I want to have a menu structure like this:

<ul>
    <li><a href="/">Home</a></li>
    <li>
        <a href="#">Stuff</a>
        <ul>
            <li><a href="/Stuff/"<li>
            <li><a href="/Stuff/Add"<li>
        </ul>
    </li>
</ul>

我正在使用不带xml的MvcSiteMapNode;只是装饰者的方式.

I am using MvcSiteMapNode without xml; just with the decorator's way.

所以我有这个控制器:

[MvcSiteMapNode(Title = "Stuff", ParentKey = "root", Key = "stuff-key", Url = "#", ImageUrl = "fa-stuff")] 
public class StuffController : Controller {

    [MvcSiteMapNode(Title = "List", ParentKey = "stuff-key", Key = "stuff-list")]
    public ActionResult Index(){}

    [MvcSiteMapNode(Title = "Add", ParentKey = "stuff-key", Key = "stuff-add")]
    public ActionResult Add(){}
}

我的问题是,当我获取url/Stuff/时,未选择索引节点,而是仅选择了父节点(stuff-key).即使我GET/Stuff/Index发生的情况也一样.

My problem is that when I GET the url /Stuff/ the index node is not selected and is only selected the parent node(stuff-key). Even when I GET /Stuff/Index happens the same.

推荐答案

这里有2个问题:

  1. 您刚刚发现(感谢)一个错误,该错误允许在显式设置URL或无法单击节点时匹配路由值.
  2. 技术上不允许将字符#"用作URL.您可以,但这将具有转到"/#"(主页)的效果,这可能不是您想要的.

我猜想第二个问题,您想使节点成为分组目的,在这种情况下,应使其不可单击.

I am guessing for the second issue you wanted to make a node for grouping purposes, in which case it should be made non-clickable.

[MvcSiteMapNode(Title = "Stuff", ParentKey = "root", Key = "stuff-key", Clickable = false, ImageUrl = "fa-stuff")] 

这使它为东西"生成纯文本,而不是超链接.

This makes it generate plain text for "Stuff", not a hyperlink.

<ul id="menu">
    <li>
        <a href="/" title="Home">Home</a>
    </li>
    <li>
        Stuff
        <ul>
            <li>
                <a href="/Stuff" title="List">List</a>
            </li>
            <li>
                <a href="/Stuff/Add" title="Add">Add</a>
            </li>
        </ul>        
    </li>
</ul>

但是,请注意,在我发布补丁之前,匹配问题不会消失.因此,只有在高于4.5.1的版本可用时,它才可以正常工作.

However, do note the matching problem won't go away until I get the patch released. So it won't work right until a version higher than 4.5.1 is available.

这篇关于MvcSiteMapProvider菜单,在Asp.Net Mvc 5的Controller类中具有过滤器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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