对于观念的转变查找规则 [英] Change lookup rule for views
问题描述
我有被在多个国家推出了一个应用程序。将有在web.config文件中的设置,定义的国家。
该国将不会在URL中。
有些取决于该国的看法的变化。
我第一次尝试是使用一个文件夹中包含的研究观点文件夹内,如果他们从默认视图不同:
默认
/questions/ask.aspx
西班牙
/questions/ESP/ask.aspx
如果没有在国家的文件夹的默认视图不使用视图。有没有一种方法来扩展视图引擎来查找在全国第一个文件夹的看法?
编辑:
这仅仅是一个POC。要查看完整的实现看看
http://pietschsoft.com/?tag=/mvc
私有静态字符串[] = LocalViewFormats 新的String [] {
〜/查看/ {1} / ESP / {0}的.aspx
〜/查看/ {1} / {0}的.aspx
〜/查看/ {1} / {0}的.ascx
〜/查看/共享/ {0}的.aspx
〜/查看/共享/ {0}的.ascx
}; 公共LocalizationWebFormViewEngine()
{
ViewLocationFormats = LocalViewFormats;
}
公共类MyViewEngine:WebFormViewEngine
{
私人静态字符串[] = LocalViewFormats新[] {〜/查看/ ESP / {0}的.aspx
〜/查看/ ESP / {0}的.ascx};
公共MyViewEngine()
{
ViewLocationFormats = LocalViewFormats.Union(ViewLocationFormats).ToArray();
}
}
显然,你不想硬code中的位置,但是这应该给你的总体思路。
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;
}
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.
这篇关于对于观念的转变查找规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!