Rendering URLs

Render Page URLs and Media URLs in Razor functions

To render a page URL or a media URL in a C1 CMS compliant way, use ~/page(...) and ~/media(...):

@inherits RazorFunction

@functions {
    public DataReference<IPage> Page { get; set; }

    public DataReference<IMediaFile> Image { get; set; }        
}

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>

  <body>
    <a href="/page(@Page)">
		<img src="/media(@Image)"  alt="..."/>
	</a>
  </body>  
</html>

Download the sample

Alternatively, you can use the ad-hoc helper methods from the Html helper: PageUrl and MediaUrl:

@inherits RazorFunction

@functions {
    public DataReference<IPage> Page { get; set; }

    public DataReference<IMediaFile> Image { get; set; }        
}

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>

  <body>
    <a href="@Html.C1().PageUrl(@Page)">
      <img src="@Html.C1().MediaUrl(@Image)"  alt="..."/>
	</a>
  </body>  
</html>

Download the sample