Search code examples
razornancy

How to get the path to a Nancy Razor view inside a view?


I am trying to write an extension method which will be used inside a razor view to get the file path to said view.

I have tried putting the extension method on HtmlHelpers<T> and NancyRazorViewBase but cannot seem to get the correct information from the view or from the render context e.g.

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()"/>

Is it possible to get the path to the current view from inside the view?

I am using Nancy 0.23.


Solution

  • I had overlooked the properties on NegotiationContext e.g. view.RenderContext.Context.NegotiationContext.ViewName.