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
[PublicApi]
public interface IParameters : IReadOnlyDictionary<string, string>, IReadOnlyCollection<KeyValuePair<string, string>>, IEnumerable<KeyValuePair<string, string>>, IEnumerable, ITyped
- Inherited Members
Remarks
- uses the Convention: Functional API (Immutable)
- Added typed accessors such as
Int(...)
etc. in v16.03 implementing ITyped - Made order of parameters automatically sort in 18.06 because of crawler-load issues
- Added
Prioritize
in v18.06
Methods
Add(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)
IParameters Add(string key)
Parameters
key
string
Returns
- IParameters
A new IParameters, the original is not modified.
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)
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.
IParameters Add(string key, object value)
Parameters
key
stringthe key
value
objectobject! value
Returns
- IParameters
A new IParameters, the original is not modified.
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)
IParameters Add(string key, string value)
Parameters
Returns
- IParameters
A new IParameters, the original is not modified.
ContainsKey(string)
Check if this typed object has a property of this specified name. It's case-insensitive.
bool ContainsKey(string name)
Parameters
name
stringthe name like
Image
; some objects also support path to sub-property likeAuthor.Name
Returns
Remarks
Adding in 16.03 (WIP)
Filter(string)
Filter all parameters to only keep the keys listed in names
.
IParameters Filter(string names)
Parameters
names
stringone or more names to keep, comma-separated.
Returns
- IParameters
A new IParameters, the original is not modified.
Remarks
Added in v17.01
Flush()
Flush all parameters and start anew. Note that it does preserve other settings like prioritization.
IParameters Flush()
Returns
Remarks
New v18.06
Get(string)
Get a parameter.
🪒 Use in Dynamic Razor: CmsContext.Page.Parameters.Get("SortOrder")
🪒 Use in Typed Razor: MyPage.Parameters.Get("SortOrder")
string Get(string name)
Parameters
name
stringthe key/name in the url
Returns
- 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")
TValue Get<TValue>(string name)
Parameters
name
stringKey/name of the parameter
Returns
- TValue
Type Parameters
TValue
Remarks
Added v15.04
Get<TValue>(string, NoParamOrder, 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)
TValue Get<TValue>(string name, NoParamOrder noParamOrder = default, TValue fallback = default)
Parameters
name
stringKey/name of the parameter
noParamOrder
NoParamOrderfallback
TValueOptional fallback value to use if not found
Returns
- TValue
Type Parameters
TValue
Remarks
Added v15.04
Prioritize(string)
Prioritize the order of parameters. This allows you to order the parameters in a certain way, which can be important for some systems.
Remember:
- If a parameter doesn't exist, it still won't appear in the list
- If you order the parameters, this can have an unexpected effect on the amount of URLs you generate, possibly causing high server load when crawlers visit.
IParameters Prioritize(string fields = null)
Parameters
fields
stringCSV of names to prioritize, in the specified order
Returns
Remarks
New in v18.06.
Remove(string)
Remove a parameter and return a new IParameters.
IParameters Remove(string name)
Parameters
name
string
Returns
- IParameters
A new IParameters, the original is not modified.
Remove(string, object)
Remove a parameter value and return a new IParameters.
This only removes a specific value, for example if you start with id=27&id=42
and remove id=27
, then the result will be id=42
.
IParameters Remove(string name, object value)
Parameters
name
stringvalue
object
Returns
- IParameters
A new IParameters, the original is not modified.
Remarks
Added in v17.01
Set(string)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will just overwrite it.
IParameters Set(string name)
Parameters
name
string
Returns
- IParameters
A new IParameters, the original is not modified.
Set(string, object)
Add another URL parameter and return a new IParameters. If the name/key already exists, it will just overwrite it.
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.
IParameters Set(string name, object value)
Parameters
name
stringthe key
value
objectobject! value
Returns
- IParameters
A new IParameters, the original is not modified.
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.
IParameters Set(string name, string value)
Parameters
Returns
- IParameters
A new IParameters, the original is not modified.
ToString()
ToString() is specially implemented, to give you the parameters again as they were originally given on the page.
string ToString()
Returns
Toggle(string, object)
Toggle a parameter value and return a new IParameters.
This means that if the parameter was previously set with the same value, it will be un-set, otherwise it will be added.
IParameters Toggle(string name, object value)
Parameters
name
stringvalue
object
Returns
- IParameters
A new IParameters, the original is not modified.
Remarks
Added in v17.01