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 5939621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:51:14+00:00 2026-05-22T15:51:14+00:00

I’m using the following route to handle localization on my ASP.NET MVC Application routes.MapRoute(Globalization,

  • 0

I’m using the following route to handle localization on my ASP.NET MVC Application

            routes.MapRoute("Globalization", "{culture}/{controller}/{action}/{id}",
            new
            {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            });

So the scheme is http://mysite.com/en-US/Contact or http://mysite.com/es-ES/Contact

I’m trying to make some culture links in _Layout.cshtml in order to switch culture. But i need to only switch culture and stay on the same view.

Current View : http://mysite.com/en-US/Contact

=> Switch To es-ES

New View : http://mysite.com/es-ES/Contact

How can i perform that ?

Thanks.

  • 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-22T15:51:15+00:00Added an answer on May 22, 2026 at 3:51 pm

    This is quite tricky actually. You could simply use @Html.ActionLink("Spanish", null, new { @culture = "es-ES" }), however this will preserve only parameters defined in route and query string will be lost in localized version. Because of this I’ve written following helper:

    /// <summary>
    /// Returns current url modified by parameters
    /// </summary>
    /// <param name="context">Relevant request context</param>
    /// <param name="withRouteValues">Values to add or override</param>
    /// <param name="withoutRouteValues">Values to remove if present</param>
    /// <returns>Url</returns>
    public static RouteValueDictionary Current(RequestContext context, RouteValueDictionary withRouteValues = null, string[] withoutRouteValues = null)
    {
        var with = withRouteValues ?? new RouteValueDictionary();
        var without = withoutRouteValues ?? new string[0];
    
        var result = new RouteValueDictionary();
    
        var queryString = context.HttpContext.Request.QueryString;
        foreach (var key in queryString.AllKeys.Where(k => !IgnoreValues.Contains(k) && !without.Contains(k)))
            result[key] = queryString[key];
    
        var routeValues = context.RouteData.Values;
        foreach (var pair in routeValues.Where(p => !IgnoreValues.Contains(p.Key) && !without.Contains(p.Key)))
            result[pair.Key] = pair.Value;
    
        foreach (var pair in with.Where(p => !IgnoreValues.Contains(p.Key) && !without.Contains(p.Key)))
            result[pair.Key] = pair.Value;
    
        return result;
    }
    
    /// <summary>
    /// Returns anchor element with current url modified by parameters
    /// </summary>
    /// <param name="self">Html helper</param>
    /// <param name="linkText">The inner text of anchor element</param>
    /// <param name="withRouteValues">Values to add or override</param>
    /// <param name="withoutRouteValues">Values to remove if present</param>
    /// <returns>Anchor element</returns>
    public static MvcHtmlString CurrentLink(this HtmlHelper self, string linkText, object withRouteValues = null, string[] withoutRouteValues = null)
    {
        var routeValues = Current(self.ViewContext.RequestContext, withRouteValues, withoutRouteValues);
    
        return self.ActionLink(linkText, null, routeValues);
    }
    

    With this @Html.CurrentLink("Spanish", new { culture = "es-ES" }) should accomplish exactly what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.