向 Html.MenuItem 添加类
我有一个由 MVC 2 生成的菜单项的 HTML 列表。
<%= Html.MenuItem("Home", "Home", "Index")%>
<%= Html.MenuItem("Login", "Login", "Account")%>
它以 HTML 形式生成:
<li>
<a href="Index">Home</a>
</li>
<li>
<a href="Account">Login</a>
</li>
如何为列表中的每个项目将 CSS 类添加到列表中的元素?
I've got a HTML list of menu items generated by MVC 2.
<%= Html.MenuItem("Home", "Home", "Index")%>
<%= Html.MenuItem("Login", "Login", "Account")%>
Which generate in HTML:
<li>
<a href="Index">Home</a>
</li>
<li>
<a href="Account">Login</a>
</li>
How can I add a CSS class to the element in the list for each item in the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测这个 MenuItem 是您编写的或从某人那里获取的扩展方法,我还猜测他们正在包装 ActionLink 方法,如:
如果是这种情况,只需将 css 类作为参数并使用接受 htmlattributes 的 ActionLink,如下所示:
然后你只需这样调用它们:
I am guessing this MenuItem is an extension method that you wrote or that you took from someone, I am also guessing that they are wrapping an ActionLink Method, As in:
if this is the case just make it take is a css class as a parameter and use the ActionLink that takes in htmlattributes, as in:
then you just call them like this: