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:
Compiler Error Message: BC30988: Type or 'With' expected.
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.
If you do not want to pass in a variable you can do the following: Html. ActionLink("View Performances", "Details", "Productions", null, new {@class = "button"}) if you just want to add the class. Also, the "Productions" part of this element is not required.
If you need to pass through the reference to an object that is stored on the server, then try setting a parameter of the link to give a reference to the object stored on the server, that can then be retrieved by the action (example, the Id of the menuItem in question).
Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.
@ewomack has a great answer for C#, unless you don't need extra object values. In my case, I ended up using something similar to:
@Html.ActionLink("Delete", "DeleteList", "List", new object { }, new { @class = "delete"})
In C# it also works with a null as the 4th parameter.
@Html.ActionLink( "Front Page", "Index", "Home", null, new { @class = "MenuButtons" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With