In an ASP.NET MVC aspx page I have the following script:
<script type="text/c#" runat="server">
string rl = Request.RawUrl;
</script>
the Request is underlined in Visual Studio with the following error:
An object reference is required for the non-static method, field, or property System.Web.UI.Page.Request.get
However this: <%=Request.RawUrl%> works fine.
Can you please tell me how I can get the RawUrl into the rl string variable in the script? Thanks!
This is a continuation of How to make a variable on an aspx page visible to multiple content sections on that page in ASP.NET MVC?
I basically am trying to declare an object on the page and referring to it in different parts of the page.
Like that:
or in your particular case:
UPDATE:
According to your comment you want to use this variable from everywhere. In this case I would recommend you writing a custom helper that will be accessible in all views:
and then when you need the value somewhere: