dotnet / dotnet/aspnetcore

minimal api-- FromQuery problem for complex object

Open
#55,719 11 comments 1 reaction 0 assignees View on GitHub
area-minimal Needs: Attention :wave:
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and Motivation
when i use web api (mvc)
```
public class ShoppingCartController : Controller
{
[HttpGet]
[Route("estimate/{sku}/{shoppingCartId?}")]
public async Task> EstimateProductAsync(
string sku,
string? shoppingCartId,
[FromQuery] Address? shipping,
[FromQuery] Address? billing
)
)
```
everything is working as expected.
=========

but when i use minimal api, got exception
```
public static IEndpointRouteBuilder AddEstimateProductAsyncEndpoint(this ```
IEndpointRouteBuilder builder)
{
builder.MapGet("api/ShoppingCart/EstimateProduct/{sku}/{shoppingCartId}", EstimateProductAsync)
.AllowAnonymous()
.DisableAntiforgery();
return builder;
}
private static async Task EstimateProductAsync(
string sku,
string? shoppingCartId,
[FromQuery] Address? shipping,
[FromQuery] Address? billing
)
```
which indicated both [FromQuery] Address? shipping,
[FromQuery] Address? billing are UNKNOWN AND SHOULD HAVE TryParce method
## Proposed API
minimal api should be better than mvc api , at least the same

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.