1.4 KiB
1.4 KiB
title | description | author | monikerRange | ms.author | ms.date | uid |
---|---|---|---|---|---|---|
ASP0003: Do not use action results with route handlers | Learn about analysis rule ASP0003: Do not use action results with route handlers | safia | >= aspnetcore-6.0 | riande | 10/21/2021 | diagnostics/asp0003 |
ASP0003: Do not use model binding attributes with route handlers
Value | |
---|---|
Rule ID | ASP0003 |
Category | Usage |
Fix is breaking or non-breaking | Non-breaking |
Cause
A route handler delegate includes a parameter that has a [Bind]
attribute.
Rule description
Route handler endpoints only support a subset of MVC attributes such as [FromRoute]
, [FromBody]
, etc. Unsupported attributes are ignored and result in unexpected binding behavior. For example, the following code results in an analyzer warning:
app.MapGet("/todos/{id}", ([Bind] int id) => new Todo { Id = id });
How to fix violations
To fix a violation of this rule, make sure that the endpoint uses one of the allowed model binding attributes.
app.MapGet("/todos/{id}", ([FromRoute] int id) => new Todo { Id = id });
When to suppress warnings
Do not suppress a warning from this rule. An incorrect model binding setup can result in unexpected behavior when resolving parameters at runtime.