You've been asked to build a feature where the application should display products based on categories like /products/electronics or /products/books. How can you design your routes using attributes to achieve this?

  • Use [Route("products/{category}")] on the action method
  • Modify the Global.asax file
  • Configure routes in web.config
  • Use [RoutePrefix("products/{category}")] on the controller
To achieve this, you can use attribute routing with a parameter placeholder like {category} in the route template. By applying [Route("products/{category}")] to the action method, you can ensure that products are displayed based on the specified category in the URL.
Add your answer
Loading...

Leave a comment

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