views:

1137

answers:

4

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.

Thanks in advance for any help.

A: 

deleted the c#... here is the vb.net

<%=Html.ActionLink("Home", "Index", "Home", New With {.class = "tab"}, Nothing)%>
rajesh pillai
Bad syntax for Vb.net and there is no constructor with this signature
Eduardo Molteni
sorrry... by default...i took c#.. should have been more careful reading the question..
rajesh pillai
+6  A: 

It is:

<%=Html.ActionLink("Home", "Index", MyRouteValObj, new with {.class = "tab" })%>

If 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).

Eduardo Molteni
A: 

There is no such a signature for Html.ActionLink method with (string, string, string, object).

twk
+1 because you are right
Eduardo Molteni
But the question was "How do I apply a CSS class to html.ActionLink in ASP.NET MVC?", so this didn't answer the question whatsoever.
Kezzer
+1  A: 

In VB.NET

<%=Html.ActionLink("Contact Us", "ContactUs", "Home", Nothing, New With {.class = "link"})%>

This will assign css class "link" to the Contact Us.

This will generate following HTML :

<a class="link" href="www.domain.com/Home/ContactUs">Contact Us</a>
H Sampat