 | HelpersUrlAction Method |
Generates a fully qualified URL to an action method.
Namespace: HandlebarsDotNet.MvcAssembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntaxpublic static void UrlAction(
TextWriter writer,
Object context,
params Object[] arguments
)
Public Shared Sub UrlAction (
writer As TextWriter,
context As Object,
ParamArray arguments As Object()
)
public:
static void UrlAction(
TextWriter^ writer,
Object^ context,
... array<Object^>^ arguments
)
static member UrlAction :
writer : TextWriter *
context : Object *
arguments : Object[] -> unit
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:
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:
{{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")}}
/
/Home/Contact/support?extra=greetings#fragment
/Account/Login
%2fAccount%2fLogin
See Also