Click or drag to resize
HelpersUrlAction Method
Generates a fully qualified URL to an action method.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
public static void UrlAction(
	TextWriter writer,
	Object context,
	params Object[] arguments
)

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterMvcHelpers is called. If so, it is registered as url_action but you can choose your own name for this:
C#
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("url_action", HandlebarsDotNet.Mvc.Helpers.UrlAction);
It works like https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.action.aspx.

Usage

{{url_action [controller=...] [action=...] [protocol=...] [host=...] [fragment=...] [key=value ...]}}

Arguments

controller
string (optional) - The name of the controller (without "Controller").
action
string (optional) - The name of the action.
protocol
string (optional) - The protocol for the URL, such as "http" or "https".
host
string (optional) - The host name for the URL.
fragment
string (optional) - The "fragment" for the URL (a named anchor).
the rest
(optional) - The rest of the attributes are used as route values.

Description

This helper generates a URL from the routing table using the specified arguments.
The URL that is rendered has a format like the following:

/Home/About

If special characters in the URL must be encoded, use the url_encode helper. For the previous example, the url_encode helper renders the following string:

%2fHome%2fAbout
Examples
This example assumes this helper has been registered as "url_action", the application is installed in the web root, and that the default routes are used:
view.hbs
{{url_action controller="Home" action="Index"}}
{{url_action controller="Home" action="Contact" fragment="fragment" id="support" extra="greetings"}}
{{url_action controller="Account" action="Login"}}
{{url_encode (url_action controller="Account" action="Login")}}
Renders
/
/Home/Contact/support?extra=greetings#fragment
/Account/Login
%2fAccount%2fLogin
See Also