#2 Linking with Number Url Parameters
Requirements
Resources
Linking with Number Url Parameters
The samples can differ based on your Razor base class or if you're running an old version.
Selected: Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Selected: Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
When you expect a number, you usually need to convert it to an int
or similar for further use. Otherwise you'll be comparing numbers with strings. For example if (3 == "3")
would return false
- which is not what you usually want.
Additionally, you usually want to ensure that if no parameter is found, you will have a default value - othertise you may run into errors.
⬇️ Result | Source ➡️
Click on the links to change the url-parameters of this page and see the results below.
-
Raw id from URL:
Equal to string "27": False
Equal to number 27: (would throw error)
-
Number id from URL: 0
Equal to string "27": (would throw error)
Equal to number 27: False
-
Number id from URL or -1: -1
Equal to string "27": (would throw error)
Equal to number 27: False
#2 Linking with Number Url Parameters