views:

155

answers:

1

I have an application that gets rolled out in multiple countries. There will be a setting in the web.config file, that defines the country. The country will not be in the URL.

Some of the the views change depending on the country. My first attempt is to use a folder inside the views folder that contains views, if they differ from the default view:

Default

/questions/ask.aspx

Spain

/questions/ESP/ask.aspx

If there is no view in the country-folder the default view is used. Is there a way to extend the ViewEngine to lookup views in the country folder first?

EDIT:

This is a poc only. To see a full implementation have a look at

http://pietschsoft.com/?tag=/mvc

      private static string[] LocalViewFormats = 

       new string[] {
           "~/Views/{1}/ESP/{0}.aspx",
        "~/Views/{1}/{0}.aspx",
        "~/Views/{1}/{0}.ascx",
        "~/Views/Shared/{0}.aspx",
        "~/Views/Shared/{0}.ascx"
    };

      public LocalizationWebFormViewEngine()
      {      
        ViewLocationFormats = LocalViewFormats; 
    }
+1  A: 
public class MyViewEngine : WebFormViewEngine
{
    private static string[] LocalViewFormats = new[] { "~/Views/ESP/{0}.aspx",
                                                          "~/Views/ESP/{0}.ascx" };
    public MyViewEngine()
    {
        ViewLocationFormats = LocalViewFormats.Union(ViewLocationFormats).ToArray();
    }
}

Obviously, you don't want to hardcode the location, but this should give you the general idea.

Craig Stuntz
This worked. But what do you mean by "Union" ?
Malcolm Frexner
It's an extension method in System.Linq
Craig Stuntz