App


Basics: Linking and URL Parameters

Tutorial HomeLinking
Requirements
Resources

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 ➡️

View 2

Page parameters: id=46294&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/.*