MVC2:如何判断actionlink是否指向当前页面?
我想在指向当前 URL 时将“当前”之类的类名应用于操作链接(在主视图中),以便在 UI 中指示“开启状态”。我该怎么做?
更新:我了解如何应用属性,我只需要知道如何让 actionlink 知道它指向当前页面。
I want to apply a class-name like "current" to an actionlink (in the master view) when it points to the current URL, in order to indicate an "on-state" in the UI. How might I do this?
UPDATE: I understand how to apply an attribute, I just need to know how to get the actionlink to know that it is pointing to the current page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑 MVC 的 ViewContext.RouteData.Values["action"] 对此很有用。 RouteData 具有一系列键/值对(例如此处提到的操作),允许您检索有关当前页面和当前正在使用的“视图状态”(为了需要更好的描述)的信息。
I suspect MVC's
ViewContext.RouteData.Values["action"]
would be useful for this. The RouteData has a range of key/value pairs (such as the Action mentioned here) that allow you to retrieve information about the current page and "view state" (for want of a better description) you're currently working with.如果它仅用于可见用途,我将使用 javascript 和 jQuery 来快速为“当前”链接添加一个类
if it is only for visible use, I would use javascript with jQuery to quickly add a class for the 'current' link