Interface IParameters
Collection of url parameters of the current page
Note: Has a special ToString() implementation, which gives you the parameters for re-use in other scenarios.
🪒 In Dynamic Razor it's found on CmsContext.Page.Parameters
🪒 In Typed Razor it's found on MyPage.Parameters
Inherited Members
Namespace: ToSic.Sxc.Context
Assembly: ToSic.Sxc.dll
Syntax
[PublicApi]
public interface IParameters : IReadOnlyDictionary<string, string>, IReadOnlyCollection<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>, IEnumerable, ITyped
Remarks
- uses the Convention: Functional API (Immutable)
- Added typed accessors such as
Int(...)
etc. in v16.03 implementing ITyped
Methods
| Improve this Doc View SourceAdd(string)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will extend it, add a simple Otherwise please use Set(string, string)
Important: this does not change the current object, it returns a new object.
Declaration
IParameters Add(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key |
Returns
Type | Description |
---|---|
IParameters |
Add(string, object)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will extend it, so the parameter will have 2 values. Otherwise please use Set(string, string)
Important: this does not change the current object, it returns a new object.
Note also that this takes an object
and will do some special conversions.
For example, bool values are lower case true
|false
, numbers are culture invariant and dates
are treated as is with time removed if it has no time.
Declaration
IParameters Add(string key, object value)
Parameters
Type | Name | Description |
---|---|---|
string | key | the key |
object | value | object! value |
Returns
Type | Description |
---|---|
IParameters | A new IParameters object |
Remarks
Added in v15.0
Add(string, string)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will extend it, so the parameter will have 2 values. Otherwise please use Set(string, string)
Important: this does not change the current object, it returns a new object.
Declaration
IParameters Add(string key, string value)
Parameters
Type | Name | Description |
---|---|---|
string | key | the key |
string | value | the value |
Returns
Type | Description |
---|---|
IParameters | A new IParameters object |
ContainsKey(string)
Check if this typed object has a property of this specified name. It's case insensitive.
Declaration
bool ContainsKey(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | the name like |
Returns
Type | Description |
---|---|
bool |
Remarks
Adding in 16.03 (WIP)
Get(string)
Get a parameter.
🪒 Use in Dynamic Razor: CmsContext.Page.Parameters.Get("SortOrder")
🪒 Use in Typed Razor: MyPage.Parameters.Get("SortOrder")
Declaration
string Get(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | the key/name in the url |
Returns
Type | Description |
---|---|
string | a string or null |
Remarks
Added v15.04
Get<TValue>(string)
Get a parameter and convert to the needed type - or return the default.
🪒 Use in Dynamic Razor: CmsContext.Page.Parameters.Get<int>("id")
🪒 Use in Typed Razor: MyPage.Parameters.Get<int>("id")
Declaration
TValue Get<TValue>(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | Key/name of the parameter |
Returns
Type | Description |
---|---|
TValue |
Type Parameters
Name | Description |
---|---|
TValue |
Remarks
Added v15.04
Get<TValue>(string, string, TValue)
Get a parameter and convert to the needed type - or return the fallback.
🪒 Use in Dynamic Razor: CmsContext.Page.Parameters.Get("id", fallback: 0)
🪒 Use in Typed Razor: MyPage.Parameters.Get("SortOrder", fallback: 0)
Declaration
TValue Get<TValue>(string name, string noParamOrder = "Params must be named (https://go.2sxc.org/named-params)", TValue fallback = default)
Parameters
Type | Name | Description |
---|---|---|
string | name | Key/name of the parameter |
string | noParamOrder | |
TValue | fallback | Optional fallback value to use if not found |
Returns
Type | Description |
---|---|
TValue |
Type Parameters
Name | Description |
---|---|
TValue |
Remarks
Added v15.04
Remove(string)
Remove a parameter and return a new IParameters.
Important: this does not change the current object, it returns a new object.
Declaration
IParameters Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name |
Returns
Type | Description |
---|---|
IParameters |
Set(string)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will just overwrite it.
Important: this does not change the current object, it returns a new object.
Declaration
IParameters Set(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name |
Returns
Type | Description |
---|---|
IParameters |
Set(string, object)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will just overwrite it.
Important: this does not change the current object, it returns a new object.
Note also that this takes an object
and will do some special conversions.
For example, bool values are lower case true
|false
, numbers are culture invariant and dates
are treated as is with time removed if it has no time.
Declaration
IParameters Set(string name, object value)
Parameters
Type | Name | Description |
---|---|---|
string | name | the key |
object | value | object! value |
Returns
Type | Description |
---|---|
IParameters | A new IParameters object |
Remarks
Added in v15.0
Set(string, string)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will just overwrite it.
Important: this does not change the current object, it returns a new object.
Declaration
IParameters Set(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
string | name | |
string | value |
Returns
Type | Description |
---|---|
IParameters | A new IParameters object |
ToString()
ToString() is specially implemented, to give you the parameters again as they were originally given on the page.
Declaration
string ToString()
Returns
Type | Description |
---|---|
string |