如何将 CSS 类应用于 ASP.NET MVC 中的 Html.ActionLink? [英] How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?
问题描述
我正在构建一个 ASP.NET MVC 应用程序,使用 VB.NET 并且我正在尝试将 css 类应用于 Html.ActionLink
使用代码:
I'm building an ASP.NET MVC application, using VB.NET and I'm trying to apply a css class to a Html.ActionLink
using the code:
<%=Html.ActionLink("Home", "Index", "Home", new {@class = "tab" })%>
但是当我运行代码时,我收到以下错误:
But when I run the code I receive the below error:
编译器错误消息:BC30988:应为类型或With".
Compiler Error Message: BC30988: Type or 'With' expected.
我是 MVC 的新手,我真的不知道我在做什么,所以我看不出那里有什么问题,因为我在其他地方使用基于示例的代码.
I'm new to MVC and really haven't much of a clue what I'm doing so I can't see what's wrong there as I'm using code based of an example elsewhere.
推荐答案
是:
<%=Html.ActionLink("Home", "Index", MyRouteValObj, new with {.class = "tab" })%>
在 VB.net 中,您使用
In VB.net you set an anonymous type using
new with {.class = "tab" }
并且,正如其他人指出的那样,您的第三个参数应该是一个对象(也可以是匿名类型).
and, as other point out, your third parameter should be an object (could be an anonymous type, also).
这篇关于如何将 CSS 类应用于 ASP.NET MVC 中的 Html.ActionLink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!