How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?

Tags: css,,,html-helper

Problem :

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.

Solution :

It is:

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

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

    how to make nested flexboxes work

    How can I dynamically resize a DIV element's width to fit its text content?

    How to edit menu in header - wordpress

    Show/hide stuff according to checkboxes using CSS: Why this code won´t work?

    How to apply more than 1 CSS styles in javaScript? [duplicate]

    Site Network Bar - Show Current Site Stats, CSS?

    How to set size of font with CSS without using - hyphen?

    How to select nested elements using standard CSS selectors (nth-of-type or nth-child) for Selenium?

    $(document).on(“click”… how to collapse a list when clicking anywhere else on the document

    css rules multi class, how to match two out of many

    How to place text at the bottom when there's predefined height!

    How to understand this CSS inheritance (or override, selection)

    How to get css background color on tag to span entire row

    How to reference css and script files into a node.js app?

    What is default z-Index of
    element in HTML, and how to get it using JavaScript?

    how to change the CSS background-image of a class-pseudoelement by Javascript only?

    How can I apply jQuery .css style to descendant div [closed]

    How to align tags withina div

    If you remove float: left they are centred, in combination with setting text-align: center with their parent div. That is, their immediate (first) parent div; give this an id....
    Read more

    How to apply background image to a xhtml file? [closed]

    CSS slide page up animation- element briefly shows before the animation

    While scrolling, The current div goes up, and another div under it (under the first div background) shows

    Border-bottom not showing correctly

    How to get different height html divs to float up

    How to apply SVG so that it works in IE background image

    Selecting the first-child with a given class, how? [duplicate]

    How to reduce amount of space between lines of text

    Pure CSS: Show image2 above/over/on top image1 on hover

    How to vertically center text overlapping an image?

    How to center bootstrap navba-nav on scroll when fixed?

    How can I select the item that doesn't have attribute [duplicate]