masterpage如何自己从masterpage获取当前页面
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想您可以在 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.
当您单击导航栏中(在母版页中)中的链接时,应该触发控制器操作,该操作将决定将显示哪个视图内容页面。在该操作方法中,您可以(正如 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.