Logo
Logo
  • Blazor CMS Home
  • Oqtane Tutorials
  • Blazor CMS Home
  • Oqtane Tutorials
Oqtane Tutorials
Oqtane Tutorials

Basics: Linking and URL Parameters

Tutorial Home › Linking
Linking with Modified Page Parameters
#4 Switch to view by URL
Safely Linking URLs with Umlauts and similar
Requirements
  • 2sxc 12.08
Resources
  • View Switch

Switch to view by URL

To make the views accessible through URL first follow the standard creation process...

  1. Create a new view using FAB on the views panel.
  2. In the view configuration enter a view name.
  3. Create and or select a template file.

For this tutorial we have set up two example views, see: View 1, View 2.
As seen in the example above we've made two views with the routes view1/.* and view2/.*.

To generate the URL we'll use Link.To(parameters: ...) which will build the url from the specified parameters.

⬇️ Result | Source ➡️

Make URL pointing to view

Link to view1 https://blazor-cms.org/oqtane-tutorials?data-sources-use=page&tut=basics-viewswitch&view1=whatever

Link to view2 https://blazor-cms.org/oqtane-tutorials?data-sources-use=page&tut=basics-viewswitch&view2=nice

@inherits Custom.Hybrid.Razor14

<h3>Make URL pointing to view</h3>
@{
    // We often want to preserve current url-params
    // For the tutorial it's essential, otherwise the Tutorial doesn't know where we are
    var urlParams = CmsContext.Page.Parameters;
    var view1Parameters = urlParams.Set("view1", "whatever");
    var view2Parameters = urlParams.Set("view2", "nice");
  }
<p>
  Link to view1
  <a href='@Link.To(parameters: view1Parameters)'>
    @Link.To(parameters: view1Parameters)
  </a>
</p>
<p>
  Link to view2
  <a href='@Link.To(parameters: view2Parameters)'>
    @Link.To(parameters: view2Parameters)
  </a>
</p>

Source Code of View-First.cshtml

@inherits Custom.Hybrid.Razor14

<h2>View 1</h2>
<p>
  Page parameters: <code>@CmsContext.Page.Parameters</code>
</p>

Source Code of View-Second.cshtml

@inherits Custom.Hybrid.Razor14

<h2>View 2</h2>
<p>
  Page parameters: <code>@CmsContext.Page.Parameters</code>
</p>

View-Switching based on URL Parameters

This requires the view configuration to be set to activate the details view if id is specified in the url, using id/.*

 

Linking with Modified Page Parameters
#4 Switch to view by URL
Safely Linking URLs with Umlauts and similar
  • 2sic internet solutions
  • Langäulistrasse 62, 9470 Buchs SG, Switzerland
  • +41 81 750 67 77
Login