Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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; 
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
906 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...