0

I stumbled upon this question: What is the purpose of the Name parameter in HttpPostAttribute

Which confused me at first but makes sense upon reading. However in learning about WebAPI I see the name parameter AS well as parameters for the name. Such as in the "pizza" example here:

https://learn.microsoft.com/en-us/training/modules/build-web-api-aspnet-core/8-exercise-implement-crud

[HttpPut("{id}")]
public IActionResult Update(int id, Pizza pizza)
{
    if (id != pizza.Id)
        return BadRequest();

    var existingPizza = PizzaService.Get(id);
    if (existingPizza is null)
        return NotFound();

    PizzaService.Update(pizza);

    return NoContent();
}

So on first instinct these are just meant to be placeholder local variables I assume....but microsofts documentation on IActionResult is honestly pretty thin. Is there anything specific we need to know about these parameters other than they are "local variables" that I assume get garbage collected after the request? Do they serve as a sort of property to tell the controller what objects "might" be used in the controller?

msmith1114
  • 2,717
  • 3
  • 33
  • 84
  • 1
    Your question confuses me because it starts out talking about the routing attribute and then asks about (I think) the parameters of the action method. Those two don't have much to do with each other. The parameters are used for [model binding](https://learn.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-7.0), not routing. – John Wu Mar 21 '23 at 19:42
  • @JohnWu I guess what I am talking about is the action method params, still new so I get the naming between them confused. – msmith1114 Mar 21 '23 at 20:06

0 Answers0