Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:12:40+00:00 2026-05-28T04:12:40+00:00

It seems to be simple, but I can’t get anything to work. This code

  • 0

It seems to be simple, but I can’t get anything to work. This code was generated by my template generator and needs to be changed.

<li><a href="../Home/Contact" class="active"><span class="l"></span><span class="r">
                        </span><span class="t">Nous contacter</span></a> </li>

My best bet up to now is:

    <li><span class="l"></span><span class="r"></span>
@Html.RouteLink("Contact", new { Controller = "Home", Action = "Contact" }, new { @class = "t" })</li>

But it doesn’t do anything.
Just to make sur that my question is clear: The link works in both cases, that’s fine. The formating doesn’t work. That’s my issue here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:12:41+00:00Added an answer on May 28, 2026 at 4:12 am

    The second will generate:

    <li>
        <span class="l"></span>
        <span class="r"></span>
        <a class="t" href="/Home/Contact">Contact</a>
    </li>
    

    which is different than what you had in the first place which might explain the formatting problems:

    <li>
        <a href="../Home/Contact" class="active">
            <span class="l"></span>
            <span class="r"></span>
            <span class="t">Nous contacter</span>
        </a>
    </li>
    

    The problem with Html helpers such as Html.ActionLink and RouteLink is that they by always Html encode the text, so you cannot use HTML as text. So one possibility is the following:

    <li>
        <a href="@Url.RouteUrl("Contact", new { controller = "home", action = "contact" })" class="active">
            <span class="l"></span>
            <span class="r"></span>
            <span class="t">Nous contacter</span>
        </a>
    </li>
    

    Another possibility if you have lots of those to generate is to write a custom Html helper that will do the job for you:

    public static class HtmlExtensions
    {
        public static IHtmlString MyLink(
            this HtmlHelper htmlHelper, 
            string linkText, 
            string routeName, 
            object routeValues
        )
        {
            var spans = string.Format(
                "<span class=\"l\"></span><span class=\"r\"></span><span class=\"t\">{0}</span>", 
                htmlHelper.Encode(linkText)
            );
    
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var url = urlHelper.RouteUrl(routeName, routeValues);
            var anchor = new TagBuilder("a");
            var rvd = new RouteValueDictionary(routeValues);
            var rd = htmlHelper.ViewContext.RouteData;
            var currentAction = rd.GetRequiredString("action");
            var currentController = rd.GetRequiredString("controller");
            var controller = rvd["controller"] as string;
            var action = rvd["action"] as string;
            if (string.Equals(controller, currentController, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(action, currentAction, StringComparison.OrdinalIgnoreCase))
            {
                anchor.AddCssClass("active");
            }
            anchor.Attributes["href"] = url;
            anchor.InnerHtml = spans;
            return new HtmlString(anchor.ToString());
        }
    }
    

    and then:

    <li>
        @Html.MyLink("Nous contacter", "Contact", new { controller = "home", action = "contact" })
    </li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like something simple but I can't seem to get it to work.
This seems painfully simple, but I can't work out how to do it: I
This one seems to be a simple problem, but I can't make it work
Seems pretty simple but I can't get it to work. I have two divs
This seems like it should be simple but I can't find anything yet. In
This seems like it should be simple but I can't work out how to
This seems like it should be simple but I can't work it out from
This seems simple but I can't figure it out. I receive post data in
This seems like a simple question, but I can't find it with the Stack
Ok, this seems simple but I can't find a solution to save my life.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.