views:

127

answers:

2

Hi guys

I have a base controller that I use to return basic views like this.

  public ActionResult Index(string pageName)
        {
            return View(pageName);
        }

        public ActionResult LanguageSpecific(string ul, string pageName)
        {
            var result = View("sv/" + pageName);

            return View(result.ViewName);
        }

The controller's name is home is there a way that for it not to look for the sv content in /home but just in /sv

  "EnglishRoute",                                              // Route name
                "{pageName}.aspx",                           // URL with parameters
                new { controller = "Home", action = "Index", pageName = "" }  // Parameter defaults
            );

            routes.MapRoute(
              "SwedishRoute",                                              // Route name
              "{ul}/{pageName}.aspx",                           // URL with parameters
              new { controller = "Home", action = "LanguageSpecific", ul = "",pageName = "" }  // Parameter defaults
          );

It looks in these locations:

  • ~/Views/Home/sv/index.aspx
  • ~/Views/Home/sv/index.ascx
+1  A: 

When you call the View method you can pass in an app-relative path that starts with "~/" and then ASP.NET MVC will use the exact path you specify:

return View("~/UseExactlyThisFile.aspx");

That way it won't do its search in the various paths and locations that are pre-configured.

Please keep in mind that this doesn't have very much to do with routing (though it does a little bit).

Eilon
+1  A: 

If you try to localize your pages, why don't you use resources? With the pattern above you don't really take the advantages of mvc. Or do i misunderstand you? A simple solution would be to use an action filter which picks up the language identifier from the route and sets the UICulture. The Views then may use resources to localize their content.

Claus Trojahn