Topic | Value |
---|---|
Id | ASP001 |
Severity | Warning |
Enabled | True |
Category | AspNetCoreAnalyzers.Routing |
Code | AttributeAnalyzer |
Parameter name does not match the name specified by the route parameter.
[HttpGet(""api/orders/{id}"")]
public async Task<IActionResult> GetOrder([FromRoute]int ↓wrong)
{
var match = await this.db.Orders.FirstOrDefaultAsync(x => x.Id == wrong);
if (match == null)
{
return this.NotFound();
}
return this.Ok(match);
}
In the above example the route parameter id
has not matching parameter in the method.
Use the code fix to change it to:
[HttpGet(""api/orders/{id}"")]
public async Task<IActionResult> GetOrder([FromRoute]int id)
{
var match = await this.db.Orders.FirstOrDefaultAsync(x => x.Id == id);
if (match == null)
{
return this.NotFound();
}
return this.Ok(match);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable ASP001 // Parameter name does not match the name specified by the route parameter
Code violating the rule here
#pragma warning restore ASP001 // Parameter name does not match the name specified by the route parameter
Or put this at the top of the file to disable all instances.
#pragma warning disable ASP001 // Parameter name does not match the name specified by the route parameter
[System.Diagnostics.CodeAnalysis.SuppressMessage("AspNetCoreAnalyzers.Routing",
"ASP001:Parameter name does not match the name specified by the route parameter",
Justification = "Reason...")]