Well done! Instead of ugly URLs like:


You can now re-define them like:


In this lesson you learned:

  • Typing a string after the @page directive will edit the page’s default route.
  • Typing parameters within curly braces after the @page directive will define a route template.
  • Route values can be made optional with a question mark ?.
  • Route values can be constrained using the colon syntax and keyword constraints.
  • The asp-route-{value} attribute can add additional information to an <a> element’s href attribute, either in the form of an additional route segment or query string, depending on how the route template is defined.
<!-- No URL segments --> @page <!-- Edit the default route --> @page "/Days" <!-- Add a route template --> @page "/Days/{day}" <!-- Constrain route value --> @page "/Days/{day:int}" <!-- Make route value optional --> @page "/Days/{day:int?}"


Experiment with the links at localhost:8000/Days/. Check that the URLs match your expectations and the code in Activity.cshtml.

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?