• Login
  • Register

Basic Tutorials

Tutorial HomeBasics

Working with URL Parameters using Page Parameters

The following code will use a value from the url querystring. There are various ways to pick it up, but we recommend the cross-platform API which works in Dnn and Oqtane.

  1. Cross-Platform (Dnn and Oqtane): @CmsContext.Page.Parameters["id"]
  2. This would just work in Dnn: @Request.QueryString["id"]

Usually you would have somepagename?id=27 in the url, and then using @CmsContext.Page.Parameters["id"] you would pick it up.
But with DNN, there is an additional processing that happens, as DNN tries to create nice URLs resulting in somepagename/id/27. But on the server, this is still treated as the ?id=27, so you still use the same method to access it. Below you'll find some links which change the url, so you can see how the output changes:


Basics: just show a text-value of sort from the Query-String

  • URL contains sort using null-check: False
  • URL contains sort using Razor.Blade (this will also return false, if sort is empty): False
  • Sort value from URL:
  • Put sort in a variable for further use:
  • Get sort from url, or if it doesn't exist, use a default value descending (uses Razor.Blade): descending

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials.

@inherits Custom.Hybrid.Razor12
<!-- unimportant stuff, hidden -->
@using ToSic.Razor.Blade;
Working with URL Parameters using Page... <!-- unimportant stuff, hidden -->
<ul>
  <li>URL contains <code>sort</code> using null-check: 
    @(CmsContext.Page.Parameters["sort"] != null)
  </li>
  <li>URL contains <code>sort</code> using <a href="https://github.com/DNN-Connect/razor-blade" target="_blank">Razor.Blade</a> (this will also return false, if sort is empty):
    @Text.Has(CmsContext.Page.Parameters["sort"])
  </li>
  <li>Sort value from URL:
    @CmsContext.Page.Parameters["sort"]
  </li>
  <li>
    Put <code>sort</code> in a variable for further use:
    @{
      var sort = CmsContext.Page.Parameters["sort"];
    }
    @sort
  </li>
  <li>
    Get sort from url, or if it doesn't exist, use a default value <code>descending</code> (uses <a href="https://github.com/DNN-Connect/razor-blade" target="_blank">Razor.Blade</a>):
    @{
      sort = Text.First(CmsContext.Page.Parameters["sort"], "descending");
    }
    @sort
  </li>
</ul>


<!-- unimportant stuff, hidden -->