Image from StyleSheet with a Link HTMLHelper

Last post 05-09-2008 2:09 PM by Syc0F3ar. 3 replies.

Sort Posts:

  • Image from StyleSheet with a Link HTMLHelper

    04-25-2008, 10:36 AM
    • Loading...
    • cmjd
    • Joined on 04-23-2008, 1:18 AM
    • Posts 2

    Hello,

    Seeking, so far to no avail, a simple solution to this problem:

    My XHTML menu images are pulled from a stylesheet.  My hard coded URLs are giving me another kind of grief (separate story).

    <li><a href="/home/about" class="aboutus"></a></li>

    In pseudo-mvc code, I'm trying to do this:

    <li>< <%= Html.ActionLink<VanillaController.AuthenticationController>( x => x.Logout(), "Logout" )%> class="Logout"></a</li>

    Suggestions very much appreciated.

     John

     

  • Re: Image from StyleSheet with a Link HTMLHelper

    04-25-2008, 11:29 AM
    • Loading...
    • Syc0F3ar
    • Joined on 02-03-2003, 10:13 AM
    • Posts 207

    One of the overloaded methods adds a parameter for htmlAttributes. I am using preview 2, so hopefully this is there for whatever version you are using.

    public static string ActionLink<T>( Expression<Action<T>> action, string linkText, object htmlAttributes )

     Your code would be something like this:

    <li><%= Html.ActionLink<VanillaController.AuthenticationController>( x => x.Logout(), "Logout", new { class = "Logout" } )%></li>
    
     If that isn't available, you can always create the anchor tag by hand and set the href using Url.Action method.  Then you have complete control over how your anchor tag is written out.
  • Re: Image from StyleSheet with a Link HTMLHelper

    04-26-2008, 6:45 AM
    • Loading...
    • cmjd
    • Joined on 04-23-2008, 1:18 AM
    • Posts 2

    Thank you for the recommendations.

    The html attributes object does *not* like the word "class" in the anon. type. 

    Your second suggestion, however, works like a charm:

    <li> <a href="<%= Url.Action( "index", new { controller="Products" }) %>" class="catalog"> </a></li>

    Thanks!

     

     

  • Re: Image from StyleSheet with a Link HTMLHelper

    05-09-2008, 2:09 PM
    • Loading...
    • Syc0F3ar
    • Joined on 02-03-2003, 10:13 AM
    • Posts 207

    Sorry about that.  "class" is a reserved word obviously.  Just for reference later on you can put an @ sign in front of it to use reserved words as properties, variables, etc...

     So it would look something like this:

    <li><%= Html.ActionLink<VanillaController.AuthenticationController>( x => x.Logout(), "Logout", new { @class = "catalog" } )%></li>
Page 1 of 1 (4 items)