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.
Loading...
Related Quiz
- You're new to ASP.NET Core and are confused about where to specify the common design elements (like headers and footers) that appear on every page. Which Razor concept should you explore for this purpose?
- JWT or JSON Web Tokens are often used in conjunction with the _________ authentication scheme in ASP.NET Core.
- In ASP.NET Core Identity, the _________ property is often used to ensure unique user identification beyond just the username.
- In the MVC pattern, the _________ is responsible for rendering the user interface of the application.
- In ASP.NET Core Identity, the _________ option can be used to enforce password histories, ensuring users don't reuse recent passwords.