Saturday, June 16, 2018

If you do things the RESTful way in MVC you may still need an attribute at your action.

"ASP.NET Core 2 and Angular 5" by Valerio De Sanctis will have you making a controller that starts out like this if you follow along and build out the code suggested in the lessons.

[Route("api/[controller]")]
public class QuizController : Controller
{

 
 

Two of the actions inside start out like this:

  • [HttpGet("{id}")]
    public IActionResult Get(int id)
    {
     
  • [HttpGet("Latest/{num}")]
    public IActionResult Latest(int num = 10)
    {
     

See the difference? The first is like a traditional REST endpoint and the second is what the book dubs attribute-based routing even though both actions utilize attributes.

No comments:

Post a Comment