DOT

VVM

 DOCS

Version: 1.0 | 1.1 |

RouteLink

in namespace DotVVM.Framework.Controls

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

Properties

Name Type Description Notes Default Value
Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
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
Enabled Boolean
attribute
inner element
static value
bindable
default
True
ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
RouteName String Gets or sets the name of the route in the route table.
attribute
inner element
static value
bindable
default
Text String Gets or sets the text of the hyperlink.
attribute
inner element
static value
bindable
default
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
Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description

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.

HTML Rendered 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>

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

Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message