如何确定 mvc 站点地图中的当前控制器操作?
我遇到了一个问题,我无法想象我是第一个必须处理它的人。然而,谷歌没有提供任何有用的东西,SO 也没有提供任何有用的东西,所以我在这里。
我正在使用带有站点地图的 ASP.NET MVC1。我使用 html 助手创建了一个导航菜单,突出显示 Site.Master 页面中当前选定的选项。常见场景并且可以通过使用轻松完成:
foreach ( SiteMapNode subnode in node.ChildNodes) {
if (SiteMap.CurrentNode == subnode) { //got ourselves the current here }
}
这一切都很好,但是,我的问题是我有 1 个具有多个操作的控制器。考虑以下场景:
帐户 * 客户 * 供应商 * 维护
它们都将在我的 AccountController 中,进行相同的搜索,但使用不同的 AccountTypeId 值。
当我读取 SiteMap.CurrentNode 值时,它仅提供我正在使用 AccountController 的信息,而不提供我调用的操作的信息。我已经尝试了很多事情,但无法得到所请求的操作。
我希望我在那里提供了足够的信息来让您了解该场景。如果您还需要什么,请告诉我。
提前致谢 :)!
PS:自从工作了大约两个月以来,我就被扔进了asp.net,所以请耐心等待。编程经验就在这里,但 C# / .NET 知识基本上等于 Google 或同事可以为我提供的知识。
编辑:--为了回应下面鲍勃的回答--
我遇到了 SiteMap Provider 项目,但是我没有给予它太多关注,因为我使用的是 MVC1 并且它针对的是 MVC2。此外,我不太确定我们是否已经在使用它...毕竟,我有一个站点地图...并且在办公室可以告诉我的人正在放松接下来两周去某个地方的海滩:(
I'm stuck with a problem of which I can not imagine I am the first person having to deal with it. Yet, Google comes up with nothing useful and neither does SO, so here I am.
I'm using ASP.NET MVC1 with a sitemap. Using an html helper I create a navigation menu that highlights the current selected option in the Site.Master page. Common scenario and easily done by using :
foreach ( SiteMapNode subnode in node.ChildNodes) {
if (SiteMap.CurrentNode == subnode) { //got ourselves the current here }
}
That's all fine and dandy, however, my problem is that I have 1 controller with multiple actions. Consider the following scenario:
Accounts
* clients
* suppliers
* maintainance
They would all be in my AccountController, doing a search that is identical but with a different AccountTypeId value.
When I read the SiteMap.CurrentNode value it gives me merely the info that I am using the AccountController, but not which action I called. I've tried a whole bunch of things but I can not get the action that was requested.
I hope I gave enough info there to give you an idea of the scenario. If you need anything else, let me know.
Thanks in advance :)!
PS: Tossed into asp.net since about 2 months here at work so bear with me. Programming experience is here but C# / .NET knowledge is mostly equal to what Google or co-workers can provide me with.
EDIT: -- In response to bob's answer below --
I have came across the SiteMap Provider project however I didn't gave it much attention since I'm using MVC1 and it's aimed at MVC2. Additionally, I'm not quite sure if we are already using it or not...After all, I have a sitemap... And the person who could tell me at the office is chillin' on a beach somewhere for the next 2 weeks :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您看过 RouteData.Values[“action”] 吗?确定这是否有帮助有点棘手。
Have you looked at RouteData.Values["action"]. It's kind of tricky to work out if this might help.
当您搜索
mvcsitemap
时,您可以尝试这个 ASP.NET MVC SiteMap 提供程序 第一个结果在谷歌中you could try this ASP.NET MVC SiteMap provider first result when you search
mvcsitemap
in google