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 | |
---|---|---|---|---|---|
ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
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. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
Enabled | Boolean | Gets or sets a value indicating whether the link is enabled and can be clicked on. Please note that the HTML hyperlinks don't support the disabled state, so setting this property to "false" will still produce the "click" event in JavaScript. If the link is disabled, DotVVM will not perform the navigation. |
attribute
static value
bindable
|
True | |
ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
bindable
|
True | |
InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
RouteName | String | Gets or sets the name of the route in the route table. |
attribute
static value
|
null | |
Text | String | Gets or sets the text of the hyperlink. |
attribute
static value
bindable
|
||
UrlSuffix | String | Gets or sets the suffix that will be appended to the generated URL (e.g. query string or URL fragment). |
attribute
static value
bindable
|
null | |
Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
bindable
|
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>
From DotVVM 4.0, the
href
attribute is rendered even in the client-side rendering mode so even the clients without JavaScript will see the initial value.