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);
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
null
property icon ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
property icon DataContext Object Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value.
attribute
inner element
static value
bindable
default
null
property icon Enabled Boolean
attribute
inner element
static value
bindable
default
True
property icon ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
null
property icon InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
null
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
property icon Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

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>