如何更改默认视图位置方案的ASP.NET MVC?视图、如何更改、位置、方案

由网友(沐柠深巷)分享简介:我想根据当前的UI文化在运行时更改视图位置。我怎样才能做到这一点使用默认Web窗体视图引擎?I want to change view locations at runtime based on current UI culture. How can I achieve this with default Web F...

我想根据当前的UI文化在运行时更改视图位置。我怎样才能做到这一点使用默认Web窗体视图引擎?

I want to change view locations at runtime based on current UI culture. How can I achieve this with default Web Form view engine?

基本上,我想知道用 WebFormViewEngine 如何实现的东西是什么custom IDescriptorFilter 在星火。

Basically I want to know how implement with WebFormViewEngine something what is custom IDescriptorFilter in Spark.

有另一种观点引擎,它让我运行控制视图位置?

Is there other view engine which gives me runtime control over view locations?

编辑:我的网址应该看起来如下 {语言} / {控制器} / {行动} / {ID} 。我不需要语言相关的控制器和视图本地化的资源。但是少数人的意见会在某些语言不同。所以,我需要告诉视图引擎的外观的语言特定的文件夹第一。

My URLs should looks following {lang}/{controller}/{action}/{id}. I don't need language dependent controllers and views are localized with resources. However few of the views will be different in some languages. So I need to tell view engine to looks to the language specific folder first.

推荐答案

一个简单的解决办法是,在你的 Appication_Start 弄个合适视图引擎 ViewEngines.Engines 收集和更新其ViewLocationFormats阵列和PartialViewLocationFormats.无两轮牛车:它是由默认的读/写

A simple solution would be to, in your Appication_Start get hold of the appropriate ViewEngine from the ViewEngines.Engines collection and update its ViewLocationFormats array and PartialViewLocationFormats. No hackery: it's read/write by default.

protected void Application_Start()
{
    ...
    // Allow looking up views in ~/Features/ directory
    var razorEngine = ViewEngines.Engines.OfType<RazorViewEngine>().First();
    razorEngine.ViewLocationFormats = razorEngine.ViewLocationFormats.Concat(new string[] 
    { 
        "~/Features/{1}/{0}.cshtml"
    }).ToArray();
    ...
    // also: razorEngine.PartialViewLocationFormats if required
}

剃刀looks像这样:

ViewLocationFormats = new string[]
{
    "~/Views/{1}/{0}.cshtml",
    "~/Views/{1}/{0}.vbhtml",
    "~/Views/Shared/{0}.cshtml",
    "~/Views/Shared/{0}.vbhtml"
};

注意,您可能需要更新PartialViewLocationFormats也。

Note that you may want to update PartialViewLocationFormats also.

阅读全文

相关推荐

最新文章