c# - Nancy Razor 部分 View 不在 Release模式下呈现

标签 c# razor nancy

部分 View 在 Debug模式下呈现,但在 Release模式下不呈现。

堆栈跟踪

[ArgumentNullException: Value cannot be null.
Parameter name: key]
    System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +5895838
    Nancy.ViewEngines.DefaultViewCache.GetOrAdd(ViewLocationResult viewLocationResult, Func`2 valueFactory) +329
    Nancy.ViewEngines.Razor.RazorViewEngine.GetOrCompileView(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Type passedModelType) +186
    System.Dynamic.UpdateDelegates.UpdateAndExecute5(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) +401
    CallSite.Target(Closure , CallSite , RazorViewEngine , ViewLocationResult , IRenderContext , Assembly , Object ) +575
    Nancy.ViewEngines.Razor.RazorViewEngine.GetViewInstance(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Object model) +1128
    System.Dynamic.UpdateDelegates.UpdateAndExecute5(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) +401
    CallSite.Target(Closure , CallSite , RazorViewEngine , ViewLocationResult , IRenderContext , Assembly , Object ) +495
    Nancy.ViewEngines.Razor.<>c__DisplayClass1f.<RenderView>b__1e(Stream stream) +470
    Nancy.ViewEngines.Razor.HtmlHelpers`1.Partial(String viewName, Object modelForPartial) +1872
    RazorOutput.RazorView.<Execute>b__3() +632
    Nancy.ViewEngines.Razor.NancyRazorViewBase`1.ExecuteView(String body, IDictionary`2 sectionContents) +374
    Nancy.ViewEngines.Razor.<>c__DisplayClass1f.<RenderView>b__1e(Stream stream) +775
    Nancy.Hosting.Aspnet.NancyHandler.ProcessRequest(HttpContextBase context) +81
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +913
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

master.cshtml(仅相关部分)

@if (IsSectionDefined("sidebar")) {
    <div id="two-col">
        @RenderBody()
    </div>
    <div id="sidebar">
        @RenderSection("sidebar")
    </div>
} else {
    <div id="one-col">
        @RenderBody()
    </div>
}

索引.cshtml

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{ Layout = "master.cshtml"; }

// html for body, doesn't use model

@section sidebar {
    @Html.Partial("/sidebars/sidebar.cshtml", Model)
}

sidebar.cshtml(示例部分)

<ul>
@foreach (var item in Model.Items)
{
    <li>@Html.Raw(@item.DisplayText)</li>
}
</ul>

最佳答案

我最近遇到了这个问题,但链接到我的主布局页面。 查看您的索引页,它可能是两件事之一,就像我一样,母版页的路径或部分的路径。 如果您删除部分 url 上的前导斜杠,或者母版页位于共享文件夹中,请将完整路径添加到其 url(不带前导斜杠或 ~/)。

这是我找到解决方案的地方。 https://groups.google.com/forum/#!topic/nancy-web-framework/zRLth_hl2r8

HTH

关于c# - Nancy Razor 部分 View 不在 Release模式下呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18413837/

相关文章:

c# - 使用 Linq 内联定义查询参数类型 List<int> 时出错

c# - 将参数传递给 Backgroundworker 错误处理程序

c# - 在 UWP Windows 10 C# 中创建带边框的圆形按钮

css - 如何在CSS中提供动态高度

Nancy 重定向到当前模块下的路由

razor - 如何从 Nancy 将模型传递到 Razor View

c# - 为什么Covariance和Contravariance这样命名?

javascript - 在 cshtml 中的迭代表上设置 ng-bind-html

asp.net-mvc - 在 Razor Helper 中访问 ViewContext

.net - Nancy 使用 Razor : Views are cached, 使开发变得非常困难