According to this answer the way to do it in MVC Razor is @Request.RawUrl
, @Request.Url.ToString()
or @Request.Url.AbsoluteUri
.
On my razor page, ReSharper resolves @Request
to using @Nancy
, and I can't find an instance of HttpRequestBase.RawUrl.
How do I get the RawUrl from a Nancy served template?
Inject NavigationManager in razor. Use Uri from NavigationManager to get the current URL.
What is Razor? Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages. Server-based code can create dynamic web content on the fly, while a web page is written to the browser.
CSHTML files use the @ symbol and Razor reserved directives to transition from HTML markup to C# code. Most CSHTML files are created in Microsoft Visual Studio. Visual Studio provides syntax highlighting and Intellisense code suggestions that help developers create CSHTML files.
Currently you would have to either expose it on your ViewModel
or derive your own page base class form the NancyRazorViewBase<TModel>
class, and expose it from the RenderContext.Context.Request.Url
property
You can see an example of creating your own page base class here https://github.com/NancyFx/Nancy/blob/master/src/Nancy.ViewEngines.Razor.Tests/GreetingViewBase.cs
I just submitted a pull-request with a code change that makes the following possible from your Razor views https://github.com/NancyFx/Nancy/pull/1633
@Request.Url
@Context.Request.Url
As soon as the pull-request has been accepted you will be able to use it by using our bleeding edge builds https://www.myget.org/gallery/nancyfx
It will then be part of the Nancy v1-alpha release on the official Nuget feed, once we release that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With