URL Helper
The "Url" class allows you to create, modify, validate, encode, and decode URLs, and much more.
Methods
| Name | Arguments | Return Type | Description |
|---|
| Action | string action,
string controller,
object routeValues | string | Constructs a URL to an action. |
| Asset | string relativePath | string | Constructs a URL to the Magentrix Cloud CDN for a static asset. |
| Build | string baseUrl,
object routeValues | string | Merges parameters with an existing URL. |
| Domain | | string | Current portal's domain |
| Decode | string url | string | Decodes a URL string. |
| Encode | string url | string | Encodes a URL string. |
| Host | | string | Returns the HttpRequest.Host. |
| IsLocalUrl | string url | bool | Return true, if the URL is not an external URL. |
| MergeQueryString | object values1,
object value2 | RouteValueDictionary | Merges two sets of QueryString Parameters. Items in the second parameter overwrite the first one.
You can pass NameValueCollection or RouteValueDictionary or Anonymous class. |
| ParseQueryString | string url | NameValueCollection | Parses a URL string and extracts all the URL parameters. |
| ToAbsoluteUrl | string relativeUrl | string | Returns an absolute URL version of the relative URL given. |
| UpsertParameter | string name,
object value | string | Returns the current URL with modified parameter. If the parameter is not found it will be added to the URL, otherwise it will be updated within the URL. |
| UpsertParameter | string url,
string name,
object value | string | Returns the URL with modified parameter, if the parameter is not found it will be added to the URL. Otherwise it will be updated within the URL. |
The example below shows how you can construct a URL of an image loaded into Magentrix assets:
<asp:Image runat='server' imageUrl='<%# Url.Asset("home/img/myimage.png") %>'
alternativeText='My image' />