MvcContrib - 如何将区域放入 MenuBuilder ActionLink
我使用 MenuBuilder 和这样的代码:
public static MenuItem MainMenu(UrlHelper url)
{
Menu.DefaultIconDirectory = url.Content("~/Public/Images/");
Menu.DefaultDisabledClass = "disabled";
Menu.DefaultSelectedClass = "current";
return Menu.Begin(
Menu.Items("",
Menu.Action<HomeController>(p => p.Index(), "Home")
),
Menu.Items("",
Menu.Secure<HomeController>(p => p.About(), "About")
),
Menu.Items("",
Menu.Action<RegulationController>(p => p.Index(null), "Compliance")
)/* This is in the Compliance area */
).SetListClass("menu");
}
但我也使用 MvcContib Areas,并且在上面的代码中,最终菜单项位于名为“Compliance”的“区域”中。
(Mvc 应用程序中还有其他两个区域,注册区域列表中的第一个区域称为“立法”)
发生的情况如下:
呈现页面时(我使用标准 WebFormsViewEngine),Url 均使用以下方式呈现 : “立法”区域!!?
例如 http://localhost:1337/Legislation/Home 或 http://localhost:1337/Legislation/Home/About
最后 http://localhost:1337/Legislation/Regulation
前两个链接不应选择“立法”区域。最后一个菜单项应位于“合规性”区域。
如何防止在前两个链接上呈现错误的区域(立法)?
如何获取 Site.Master 中的 MenuBuilder 标记以接受“区域”属性或从每个链接的控制器中自动获取该属性?
I am using MenuBuilder with code like this:
public static MenuItem MainMenu(UrlHelper url)
{
Menu.DefaultIconDirectory = url.Content("~/Public/Images/");
Menu.DefaultDisabledClass = "disabled";
Menu.DefaultSelectedClass = "current";
return Menu.Begin(
Menu.Items("",
Menu.Action<HomeController>(p => p.Index(), "Home")
),
Menu.Items("",
Menu.Secure<HomeController>(p => p.About(), "About")
),
Menu.Items("",
Menu.Action<RegulationController>(p => p.Index(null), "Compliance")
)/* This is in the Compliance area */
).SetListClass("menu");
}
But I am also using MvcContib Areas and in the code above the final menu item is in an 'Area' called 'Compliance'.
(There are two other areas in the Mvc application and the first in the list of registered areas is called 'Legislation')
What happens is the following:
When a page is rendered (I am using the standard WebFormsViewEngine) the Urls are all rendered using the 'Legislation' area!!?
E.g. http://localhost:1337/Legislation/Home or http://localhost:1337/Legislation/Home/About
and finally http://localhost:1337/Legislation/Regulation
The first two links should not pick up the 'Legislation' area. The last menu item should be in the 'Compliance' area.
How do I prevent the erroneous Area (Legislation) being rendered on the first two links?
How do I get the MenuBuilder markup in the Site.Master to accept an 'area' attribute or get it picked up automatically from the Controller for each link?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 MvcContrib MenuBuilder 与区域不能很好地配合。最后我把这些区域拿出来,问题就消失了。
但是,我认识到 Mvc 应用程序中可能存在一些其他问题,这些问题确实可能与 MvcContrib 引用的 Mvc dll 的旧(测试版?)版本有关。
因此,对于遇到此问题的任何人来说,这可能确实不是问题。
It seems that MvcContrib MenuBuilder does not play well with Areas. In the end I took the Areas out and the problem went away.
However, I recognise there may have been some other issue in the Mvc application which may indeed have been related to the older (beta?) version of Mvc dll that MvcContrib was referencing.
So for anyone that comes across this it may indeed be a none issue.