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


Tags: css,asp.net-mvc,vb.net,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 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 Howto..

    How to move links in the middle of the Web page using html/css?

    how to change css of the image link when clicked?

    How can i inherit properties from the css id rule to the css class?

    How do you show just the first line of text of a div and expand on click?

    How to keep text in the middle of the screen even when re-sizing page in html/css

    CSS positioning: how to make it relative to one element but not the other?

    How to adapt website to user's Screen Resolution?

    How get dimension of HTML shadow element via JavaScript

    How to find the relevant stylesheet for a specific CSS code [closed]

    How to add two CSS Class to control in the code behind?

    how to position two image as a background image on div by css

    How do i shift the text in twitter bootstrap navbar to center?

    How to increase height of footer's div when browser window is resized?

    How to add a rollover effect to the text on a map

    How to position a CSS sprite background image within the element?

    How to get the header and navbar on top?

    css - how to stretch a background image across the entire window

    How to blur background img - css?

    Using CSS to create custom borders with just the corners showing

    CSS - How to Style a Selected Radio Buttons Label?

    Div / CSS / ZIndex - how to overlap pictures?

    How to add border to circular image on hover? css or jquery

    How are URLs handled inside the CSS file in CakePHP so they reference the correct location?

    How to make horizontal lines with words in the middle using CSS?

    How to add a border around a canvas?

    how to make a timeline using html, css, javascript?

    How to make ScrollPanel only visible when its inside widget is higher than it & not visible when its inside widget is shorter than it?

    CSS - How to center nested divs?

    CSS height as a variable and how to calculate 60% of total screen size

    How to use Bootstrap 3 grid if elements are tiled with different height and widths