If you have a URL like /products/5, what would be a suitable route template to capture the product's id?

  • /products/{id:int}
  • /products/{id}
  • /products/{product_id}
  • /products?id=5
To capture the product's id from a URL like /products/5, you can use the route template /products/{id}. The {id} segment is a placeholder for the product's id, and the :int constraint ensures that it must be an integer value. This allows you to retrieve and process the id as a parameter in your controller action.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *