在使用razorgenerator不同项目的同名2剃刀局部视图 [英] 2 razor partial views with the same name in different projects using razorgenerator

查看:161
本文介绍了在使用razorgenerator不同项目的同名2剃刀局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们使用的大卫Ebbo 的razorgenerator。这使我们能够我们的一些CSHTML文件移动到一个类库。

In our project we're using the razorgenerator of David Ebbo. This allowed us to move some of our cshtml files to a class library.

我们现在想实现的是以下内容:

What we would like to achieve now is the following:


  • MyCommonViews有一个MyView.cshtml在浏览文件夹中。

  • MyWebProject也有其意见文件夹中的MyView.cshtml。

  • MyOtherWebProject没有在其浏览文件夹MyView.cshtml。

当MyOtherWebProject需要加载MyView.cshtml,它会选择其中一个是在已编译MyCommonViews项目。这就是我们想要的。结果
但是当MyWebProject需要加载MyView.cshtml,我们希望它拿起重写MyView.cshtml文件,该文件是在MyWebProject本身。

When MyOtherWebProject needs to load MyView.cshtml, it will pick the one which is in the compiled MyCommonViews project. That is what we want.
BUT when MyWebProject needs to load MyView.cshtml, we would like it to pick up the "overridden" MyView.cshtml file which is in the MyWebProject itself.

是我们想可能又如何?

马努。

推荐答案

有标志 preemptPhysicalFiles = FALSE 这确实神奇。

全样本:

[assembly: WebActivator.PostApplicationStartMethod(typeof(Application.Web.Common.App_Start.RazorGeneratorMvcStart), "Start")]

namespace Application.Web.Common.App_Start
{
    public static class RazorGeneratorMvcStart
    {
        public static void Start()
        {
            var engine = new PrecompiledMvcEngine2(typeof (RazorGeneratorMvcStart).Assembly)
                             {
                                 UsePhysicalViewsIfNewer = true, //compile if file changed
                                 PreemptPhysicalFiles = false //use local file if exist
                             };

            ViewEngines.Engines.Add(engine);//Insert(0,engine) ignores local partial views

            // StartPage lookups are done by WebPages. 
            VirtualPathFactoryManager.RegisterVirtualPathFactory(engine);
        }
    }
}

但是,有可能是小bug:
HTTP://razorgenerator.$c$cplex.com/workitem/100

这篇关于在使用razorgenerator不同项目的同名2剃刀局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆