更改视图的查找规则
我有一个在多个国家/地区推出的应用程序。 web.config 文件中有一个定义国家/地区的设置。 该国家/地区不会出现在 URL 中。
有些观点因国家/地区而异。 我的第一次尝试是使用包含视图的视图文件夹内的文件夹(如果它们与默认视图不同):
Default
/questions/ask.aspx
Spain
/questions/ESP /ask.aspx
如果国家/地区文件夹中没有视图,则使用默认视图。 有没有办法扩展 ViewEngine 以首先查找国家/地区文件夹中的视图?
编辑:
这只是一个 poc。 要查看完整的实现,请查看
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,您不想对位置进行硬编码,但这应该可以让您了解总体情况。
Obviously, you don't want to hardcode the location, but this should give you the general idea.