c# - 南希.ViewEngines.ViewNotFoundException : Unable to locate view 'index.cshtml'

标签 c# razor nancy

遇到此处描述的问题 https://github.com/NancyFx/Nancy/issues/1528

具体来说,即使我按照我所理解的正确配置包括了 Razor View Engine,它也并不总是有效。自托管。

奇怪的是,我在我的 Mac(Mono/Xamarin 特定构建)或 2 台测试机器(windows/windows 构建)上没有遇到任何问题 - 它们工作得很好 - 但另外 2 台测试机器(windows/windows 构建)确实遇到了问题。

很难确定为什么会这样

使用.NET 4.5

肯定有 RAZOR 引擎 DLL 存在,甚至在 Bootstrap 中强制引用(并且没有抛出异常)

有什么线索吗?谢谢!

编辑 1:根据要求,这是完整的堆栈跟踪。我随后将其更改为明确的“index.cshtml”,但报告的错误基本相同(您只是在消息中的索引之后看到 .cshtml)。请注意缺少 cshtml 作为受支持的 View 扩展

Nancy.RequestExecutionException: Oh noes! ---> Nancy.ViewEngines.ViewNotFoundException:     Unable to locate view 'index'
Currently available view engine extensions: sshtml,html,htm
Locations inspected: views/Home/index-en-US,views/Home/index,Home/index-en-US,Home/index,views/index-en-US,views/index,index-en-US,index
Root path: XXX
If you were expecting raw data back, make sure you set the 'Accept'-header of the request to correct format, for example 'application/json'
   at Nancy.ViewEngines.DefaultViewFactory.GetRenderedView(String viewName, Object model, ViewLocationContext viewLocationContext)
   at Nancy.ViewEngines.DefaultViewFactory.RenderView(String viewName, Object model, ViewLocationContext viewLocationContext)
   at Nancy.Responses.Negotiation.ViewProcessor.Process(MediaRange requestedMediaRange, Object model, NancyContext context)
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.NegotiateResponse(IEnumerable`1 compatibleHeaders, NegotiationContext negotiationContext, NancyContext context)
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.CreateResponse(IList`1 compatibleHeaders, NegotiationContext negotiationContext, NancyContext context)
   at Nancy.Responses.Negotiation.DefaultResponseNegotiator.NegotiateResponse(Object routeResult, NancyContext context)
   at Nancy.Routing.DefaultRouteInvoker.<>c__DisplayClass9.b__5(Task`1 completedTask)
   --- End of inner exception stack trace ---
   at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)

最佳答案

确保你有有效的 Razor 配置 https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine

关于c# - 南希.ViewEngines.ViewNotFoundException : Unable to locate view 'index.cshtml' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25819504/

相关文章:

javascript - 如何使用 Breeze js 和 Nancy 实现 SaveChanges

c# - 取消路线内的任务

asp.net-mvc - 将 MVC 2 应用程序添加到 IIS 7 中的 Nancy 站点

c# - ODATA WebService,获取$元数据 C#

asp.net - 如何在 Razor View 中绑定(bind) bropdown 列表(如果 View 未与任何模型绑定(bind))

c# - 用直线而不是矩形在 Canvas 上绘制网格图案

javascript - 如何在ajax追加函数中传递变量(使用razor传递到html元素中)?

javascript - jquery无法获取隐藏字段数据

c# - Lazy<T> 在处理异常时中断

javascript - 如何从 ASP 代码隐藏调用 JavaScript 函数?