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

  • SEARCH
  • Home
  • 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 7691483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:38:06+00:00 2026-05-31T20:38:06+00:00

I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same

  • 0

I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same link just change de to en. If I am trying to get values with ViewContext.RouteData.Values[“id”]; I getting null value. Any ideas?

@Html.ActionLink("New Language", 
  ViewContext.RouteData.GetRequiredString("action"),  
  ViewContext.RouteData.GetRequiredString("controller"),
  new { lang = "en" }                            
)
  • 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-31T20:38:07+00:00Added an answer on May 31, 2026 at 8:38 pm

    You could write a custom url helper:

    public static class UrlExtensions
    {
        public static string LanguageUrl(this UrlHelper urlHelper, string lang)
        {
            var rd = urlHelper.RequestContext.RouteData;
            var request = urlHelper.RequestContext.HttpContext.Request;
            var values = new RouteValueDictionary(rd.Values);
            foreach (string key in request.QueryString.Keys)
            {
                values[key] = request.QueryString[key];
            }
            values["lang"] = lang;
            return urlHelper.RouteUrl(values);
        }
    }
    

    and then use it like this in the view:

    <a href="@Url.LanguageUrl("en")">
        <img src="@Url.Content("~/content/flag_en.jpg")" alt="en" />
    </a>
    

    and you could of course write another helper to make the rendering of the entire anchor which would use our first helper:

    public static class HtmlExtensions
    {
        public static IHtmlString ChangeLanguage(this HtmlHelper htmlHelper, string lang, string imgUrl)
        {
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var anchor = new TagBuilder("a");
            anchor.Attributes["href"] = urlHelper.LanguageUrl(lang);
            var img = new TagBuilder("img");
            img.Attributes["alt"] = lang;
            img.Attributes["src"] = urlHelper.Content(imgUrl);
            anchor.InnerHtml = img.ToString(TagRenderMode.SelfClosing);
            return new HtmlString(anchor.ToString());
        }
    }
    

    and then:

    @Html.ChangeLanguage("en", "~/content/flag_en.jpg")
    

    Now if we suppose that you navigated to /de/home/index/123?param1=value1&param2=value2, then the @Html.ChangeLanguage("en", "~/content/flag_en.jpg") would have generated the following markup:

    <a href="/en/home/index/123?param1=value1&amp;param2=value2">
        <img alt="en" src="/content/flag_en.jpg" />
    </a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following in an XML file: <entry> ... <link href=http://www.example.com/somelink /> ...
For example if location.href = 'http://mydomain.com/en/' and I have <a href=my-file.html id=myId>i am just
I have a domain www.example.com . I have created a subdirectory discount and it
I have a strange thing happening with php files. As an example: domain.com/test.php domain.com/test
For example: This is main body of my content. I have a footnote link
Does anyone have an example (code or a link) that will allow me to
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
1- Does mod_rewrite means that if I make this url: domain.com/ad.php?id=8498292 INTO domain.com/8498292 that
I have two domains, one is a .com domain and the other is a
Hey, here is the example I have a question about. I have a link:

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.