Requirements
Linking with Modified Page Parameters
Switch to Typed (2sxc 16+) Selected: Dynamic (Razor14 or below)
Preserve URL Parameters and More
In Razor page URLs are generated using Link.To(...)
. By default calling Link.To()
without any parameters returns the base URL of the site. In this case it would be: https://app-dev.2sxc.org/tutorial-razor/
.
The key to retrieving the current page URL is to pass the current page parameters. Link.To(parameters: ...)
will then construct the URL based on the passed parameters.
Current page parameters are found in CmsContext.Page.Parameters
.
Because MyPage.Parameters
/ CmsContext.Page.Parameters
follows the query string convention adding a new parameter isn't too difficult.
To add a new parameter you can use the .Add(key, value)
method or add the parameters as string following the convention as for example &name=2sxc
.
⬇️ Result | Source ➡️
See adjusted page parameters: tut=code-link-parameters-modify&variant=dyn&name=2sxc
Current page URL with new parameter from string: https://blazor-cms.org/oqtane-tutorials?tut=code-link-parameters-modify&variant=dyn&name=2sxc
Current page URL with new parameter from .Add(...)
: https://blazor-cms.org/oqtane-tutorials?tut=code-link-parameters-modify&variant=dyn&name=2sxc
To remove a parameter you can use the .Remove(key)
method or modify the string containing parameters.
⬇️ Result | Source ➡️
See adjusted page parameters:
tut=code-link-parameters-modify&variant=dyn
Current page URL with removed parameter: https://blazor-cms.org/oqtane-tutorials?tut=code-link-parameters-modify&variant=dyn
To change a parameter you can use the .Set(key, value)
method or modify the string containing parameters.
⬇️ Result | Source ➡️
See adjusted page parameters: tut=code-link-parameters-modify&variant=dyn&basics320=2sxc
Current page URL with changed parameter: https://blazor-cms.org/oqtane-tutorials?tut=code-link-parameters-modify&variant=dyn&basics320=2sxc