【问题标题】:How to get the path to a Nancy Razor view inside a view?如何在视图中获取 Nancy Razor 视图的路径?
【发布时间】:2014-08-18 08:17:20
【问题描述】:

我正在尝试编写一个扩展方法,该方法将在剃刀视图中使用以获取所述视图的文件路径。

我尝试将扩展方法放在 HtmlHelpers<T>NancyRazorViewBase 上,但似乎无法从视图或渲染上下文中获取正确的信息,例如

public static string GetPath(this NancyRazorViewBase view)
{
    //Is null, expecting something like C:\app\views\index.cshtml
    return view.Path;
}

<input type="hidden" value="@this.GetPath()"/>

是否可以从视图内部获取到当前视图的路径?

我正在使用 Nancy 0.23。

【问题讨论】:

  • 我很好奇你为什么想要这个,很遗憾我没有给你答案。也许尝试让模块在模型或 ViewBag 中设置路径?
  • 我需要用于特殊调试目的。不确定我是否可以将它附加到 ViewBag,因为这不需要我在每个路由处理程序中分配它吗?

标签: razor nancy


【解决方案1】:

我忽略了NegotiationContext 上的属性,例如view.RenderContext.Context.NegotiationContext.ViewName.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-07
    • 2012-06-08
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2018-10-18
    相关资源
    最近更新 更多