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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:25:15+00:00 2026-05-30T08:25:15+00:00

In an ASP MVC 3 project i want to enable language switching. The routing

  • 0

In an ASP MVC 3 project i want to enable language switching.

The routing is defined like this:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
             "DefaultWithLanguage", // Route name
             "{language}/{controller}/{id}/{slug}", // URL with parameters
             new { language = "en", controller = "Front", action = "Details", id = UrlParameter.Optional, slug = UrlParameter.Optional } // Parameter defaults                 
         );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

Trying to switch languages (in _Layout.cshtml) works like this:

<li>@Html.ActionLink("Spanish", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { language = "es" })</li>    

Instead of getting a URL like the following (after having selected Spanish)

.../es/ControllerName/ActionName

i ‘m getting this:

.../ControllerName/ActionName?Length=11

If i set the ActionLink to the following (notice the last null parameter):

<li>@Html.ActionLink("Spanish", ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString(), new { language = "es" }, null)</li>

i get this:

 .../ControllerName/ActionName?language=es

What am i missing?
Thanks in advance!

  • 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-30T08:25:16+00:00Added an answer on May 30, 2026 at 8:25 am

    There are some issues with your routes registration DefaultWithLanguage route registration. It doesn’t allow you to specify the {action}. This means that this route will only match a Details action (since you have specified it in the default values). Another issue is that you made the {id} parameter optional. But that’s impossible. Only the last parameter of a route can be optional. In your case it is followed by a {slug} parameter.

    So one possibility is the following:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "DefaultWithLanguage",
            "{language}/{controller}/{action}/{id}",
            new 
            { 
                language = "en", 
                controller = "Front", 
                action = "Details", 
                id = UrlParameter.Optional 
            }
        );
    }
    

    and then:

    @Html.ActionLink(
        "Spanish", 
        ViewContext.RouteData.GetRequiredString("action"), 
        ViewContext.RouteData.GetRequiredString("controller"),
        new { language = "es" },
        null
    )
    

    If you wanted to add a {slug} parameter then your {id} can no longer be optional:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "DefaultWithLanguage",
            "{language}/{controller}/{action}/{id}/{slug}",
            new 
            { 
                language = "en", 
                controller = "Front", 
                action = "Details", 
                slug = UrlParameter.Optional 
            }
        );
    }
    

    and then:

    @Html.ActionLink(
        "Spanish", 
        ViewContext.RouteData.GetRequiredString("action"), 
        ViewContext.RouteData.GetRequiredString("controller"),
        new { 
            language = "es", 
            id = ViewContext.RouteData.GetRequiredString("id") 
        },
        null
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i used one link in my asp.net mvc project like this way. <a href=<%=
I'm looking to create a fairly large-scale ASP.NET MVC project and I want to
I started my project in Asp.net MVC(c#) & SQL Server 2005.I want to implement
i need to have one project on asp.net mvc 1 but i want to
I am developing an ASP.NET MVC project and want to use strongly-typed session objects.
I have a Asp.net MVC 3 project where I want to implement a textbox
i am designing a asp.net mvc project. i want to convert my document into
I am currently developing an ASP.NET MVC project. I want to implement an ActionFilter,
I’m using git in my ASP.NET MVC project. I want no files from debug
I want to test my asp.net MVC project (being developed using Visual Studio) on

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.