RouteLink

in namespace DotVVM.Framework.Controls

Hyperlink which builds the URL from route name and parameter values.

Usage & Scenarios

Hyperlink which builds the URL from route name and parameter values.

The control has dynamic parameters. If you want to supply a value of the route parameter called "Id", use the Param-Id dynamic property.

The route configuration is in the DotvvmStartup.cs file.

The RouteLink can detect whether the page runs inside the SPA container and generate the correct URL.

Sample 1: Simple Route Links

The RouteName property is the name of the route in the route table. Routes are registered in the DotvvmStartup.cs file.

You can use property the Text property to set the text of the link.

The Param-Id="test" specifies that the {Id} parameter in the route will get the value test.

<dot:ContentPlaceHolder ID="Main" />

<menu>
  <li>
    <dot:RouteLink RouteName="SampleA" Text="Sample A"/>
  </li>
  <li>
    <dot:RouteLink RouteName="SampleB" Text="Sample B" Param-Id="test"/>
  </li>
</menu>
@masterPage master.dotmaster

<dot:Content ContentPlaceHolderID="Main">
  Content from page SampleA.
</dot:Content>
@masterPage master.dotmaster

<dot:Content ContentPlaceHolderID="Main">
  Content from page SampleB.
</dot:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotVVM.Framework.Configuration;

namespace DotvvmWeb.Views.Docs.Controls.builtin.RouteLink.sample1
{
    public class Startup : IDotvvmStartup
    {
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.RouteTable.Add("SampleA", "SampleA", "SampleA.dothtml", null);
            config.RouteTable.Add("SampleB", "SampleB/{Id?}", "SampleB.dothtml", null);
        }
    }
}

Sample 2: Set the target Attribute

You can use the target attribute to specify the way to open the link generated by the Route Link control.

It works the same way as it does with the html <a> tag.

The target="_blank" causes the browser to open the link in a new tab.

<dot:ContentPlaceHolder ID="Main" />

<menu>
  <li>
    <dot:RouteLink target="_blank" RouteName="SampleA" Text="Sample A"/>
  </li>
</menu>
@masterPage master.dotmaster

<dot:Content ContentPlaceHolderID="Main">
  Content from page SampleA.
</dot:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotVVM.Framework.Configuration;

namespace DotvvmWeb.Views.Docs.Controls.builtin.RouteLink.sample1
{
    public class Startup : IDotvvmStartup
    {
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.RouteTable.Add("SampleA", "SampleA", "SampleA.dothtml", null);
        }
    }
}

Sample 3: Set the url suffix

You can use the UrlSuffix attribute to specify the suffix that will be appended to the end of the generated url.

The Query-Id="test2" adds the Id query string parameter that will be combined with the UrlSuffix so the resulting url suffix of the sample will be ?Param=test1&Id=test2#hash.

<dot:ContentPlaceHolder ID="Main" />

<menu>
  <li>
    <dot:RouteLink RouteName="SampleA" Text="Sample A" UrlSuffix="?Param=test1#hash" Query-Id="test2"/>
  </li>
</menu>
@masterPage master.dotmaster

<dot:Content ContentPlaceHolderID="Main">
  Content from page SampleA.
</dot:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotVVM.Framework.Configuration;

namespace DotvvmWeb.Views.Docs.Controls.builtin.RouteLink.sample1
{
    public class Startup : IDotvvmStartup
    {
        public void Configure(DotvvmConfiguration config, string applicationPath)
        {
            config.RouteTable.Add("SampleA", "SampleA", "SampleA.dothtml", null);
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon Enabled Boolean
attribute
inner element
static value
bindable
default
True
property icon RouteName String Gets or sets the name of the route in the route table.
attribute
inner element
static value
bindable
default
null
property icon Text String Gets or sets the text of the hyperlink.
attribute
inner element
static value
bindable
default
property icon UrlSuffix String Gets or sets the suffix that will be appended to the generated URL (e.g. query string or URL fragment).
attribute
inner element
static value
bindable
default
null

HTML produced by the control

In the Client rendering mode, the link URL is built on the client.

<a href="#" data-bind="attr: { 'href': ... }, text: ..."></a>

In the Server rendering mode, the URL is built on the server.

<a href="...">Text or Content</a>