Imagine you have two action methods in your controller: one for handling the creation of products and another for displaying a specific product's details based on its ID. How can you utilize attribute routing to distinguish these two methods?
- [HttpGet("products/create")] and [HttpGet("products/details/{id}")]
- [Route("create")] and [Route("details/{id}")]
- [HttpGet("{controller=Products}/create")] and [HttpGet("{controller=Products}/details/{id}")]
- [HttpGet("{action=create}")] and [HttpGet("{action=details}/{id}")]
Attribute routing allows you to specify route templates for actions directly within your controller using attributes like [HttpGet] and [Route]. To distinguish the two methods, you can use attribute routing like [HttpGet("{controller=Products}/create")] for product creation and [HttpGet("{controller=Products}/details/{id}")] for displaying product details, providing clear and distinct routes for each action.
Loading...
Related Quiz
- In SignalR, what term is used to describe a group of connections that can be broadcast to?
- You're building a blog website using ASP.NET Core. When a user comments for the first time, you want to provide them with an option to create an account. Which feature of ASP.NET Core would help you accomplish this?
- What is the primary advantage of using ASP.NET Core Identity for user management in your web application?
- You're building a web application that requires different user roles like "Admin," "User," and "Guest." Using ASP.NET Core Identity, how would you restrict access to certain pages only for the "Admin" role?
- How does ASP.NET Core Identity store user data by default?