App
Requirements
Linking with Modified Page Parameters
Selected: Typed (2sxc 16+) Switch to 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: mode=one&tut=code-link-parameters-modify&view2=nice&name=2sxc
Current page URL with new parameter from string: https://oqt-apps-dev.2sxc.org/razortutorial12?mode=one&tut=code-link-parameters-modify&view2=nice&name=2sxc
Current page URL with new parameter from .Add(...)
: https://oqt-apps-dev.2sxc.org/razortutorial12?mode=one&tut=code-link-parameters-modify&view2=nice&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:
mode=one&tut=code-link-parameters-modify&view2=nice
Current page URL with removed parameter: https://oqt-apps-dev.2sxc.org/razortutorial12?mode=one&tut=code-link-parameters-modify&view2=nice
To change a parameter you can use the .Set(key, value)
method or modify the string containing parameters.
⬇️ Result | Source ➡️
See adjusted page parameters: mode=one&tut=code-link-parameters-modify&view2=nice&basics320=2sxc
Current page URL with changed parameter: https://oqt-apps-dev.2sxc.org/razortutorial12?mode=one&tut=code-link-parameters-modify&view2=nice&basics320=2sxc