Table of Contents

Interface IParameters

Namespace
ToSic.Sxc.Context
Assembly
ToSic.Sxc.dll

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

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 string

the key

value object

object! 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

key string

the key

value string

the value

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 string

the name like Image; some objects also support path to sub-property like Author.Name

Returns

bool

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 string

one or more names to keep, comma-separated.

Returns

IParameters

A new IParameters, the original is not modified.

Remarks

Added in v17.01

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 string

the 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 string

Key/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 string

Key/name of the parameter

noParamOrder NoParamOrder

see Convention: Named Parameters

fallback TValue

Optional fallback value to use if not found

Returns

TValue

Type Parameters

TValue

Remarks

Added v15.04

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 string
value 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 string

the key

value object

object! 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

name string
value string

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

string

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 string
value object

Returns

IParameters

A new IParameters, the original is not modified.

Remarks

Added in v17.01