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.
Add your answer
Loading...

Leave a comment

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