masterpage如何自己从masterpage获取当前页面

发布于 2024-08-16 13:10:53 字数 217 浏览 0 评论 0原文

我正在使用 Visual Studio 2008、C# 3.5 和 ASP.NET MVC 2 编写一个网站。我将导航栏放在母版页中。但是存在一个问题,我不知道需要在母版页中突出显示哪个按钮(当前页面)导航栏。

我想获取需要通过母版页自身突出显示的当前页面(而不是通过内容页面)。而且我认为这不是通过 url 字符串获取当前页面的好方法。因为我不知道最终的结果网址是。

那么我该怎么做呢?

I am writing a website with Visual Studio 2008, C# 3.5 and ASP.NET MVC 2. I put the navigation bar in the masterpage.But there is problem that I will not know which button is needed to be highlight(current page) in the navigation bar.

I want get the current page that need to be highlight by masterpage self (not through the content page).And I don't think it is a good way to get the current page by url string.Because I have no idea about the final url is.

So how can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

韵柒 2024-08-23 13:10:53

我想您可以在 Action 方法中设置 ViewData["currentPage"] 值,这将允许您在母版页中处理该 ViewData。然而,这超出了我的想象,我确信有一种更优雅的方法可以做到这一点。

I guess you could set a ViewData["currentPage"] value in the Action methods, this would allow you to process that ViewData in the Masterpage. That is, however, off the top of my head and I'm sure there's a more elegant way to do this.

暖伴 2024-08-23 13:10:53

当您单击导航栏中(在母版页中)中的链接时,应该触发控制器操作,该操作将决定将显示哪个视图内容页面。在该操作方法中,您可以(正如 Lazarus 建议的那样)向 ViewData 添加一些标识当前页面的数据,母版页将拾取这些数据来修改导航栏。

When you click the link in the navigation bar (in the master page) that should be triggering a controller action that will decide which view content page will be shown. In that action method you can (as Lazarus suggests) add some data identifying the current page to ViewData that will be picked up by the master page to modify the navigation bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文