【问题标题】:ASP.NET MVC ViewEngine ViewLocationCache.GetViewLocation returns nullASP.NET MVC ViewEngine ViewLocationCache.GetViewLocation 返回 null
【发布时间】:2010-01-24 12:34:23
【问题描述】:

我正在关注 Chris Pietschmann 的 solution for theming in ASP.NET MVC

我注意到的一件事是,在后续请求中没有从 ViewLocationCache 中检索视图名称。 我正在使用 ASP.NET MVC 2.0 RC

当执行以下代码时:

this.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, cacheKey, virtualPath);

然后我将鼠标悬停在 this.ViewLocationCache 上,它只返回 {System.Web.Mvc.NullViewLocationCache} - 暗示没有添加任何内容?

【问题讨论】:

    标签: asp.net asp.net-mvc viewengine


    【解决方案1】:

    ViewLocationCache 默认只在发布模式下工作(在web.config 中设置<compilation debug="false">)。

    在调试模式下启用ViewLocationCache
    在继承自 WebFormViewEngine 的自定义视图引擎中,在 ViewEngine 的构造函数中设置 ViewLocationCache,如下所示:

    public MyCustomViewEngine()
    {
        ViewLocationCache = new DefaultViewLocationCache();
    }
    

    如果您愿意,您还可以覆盖默认的缓存时间跨度值。

    【讨论】:

      猜你喜欢
      • 2010-11-22
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 2018-09-12
      • 1970-01-01
      • 2012-01-23
      相关资源
      最近更新 更多