2 Values from Route failed
mw-nfi opened this issue · comments
mw-nfi commented
- NuGet Package Version: 4.0.1
- .NET SDK Version: .net 7
I there,
i need help for my problem. I configure an endpoint with 2 [FromRoute] values, but the values are always null?
So, it is very simple but it doesn't work. I found many samples but does not work.
Here is my last code test:
Steps to Reproduce:
Endpoint.cs
public class RemoveSiteGroupRouteRequest
{
public string Request { get; set; }
public string GroupId { get; set; }
}
public class RemoveSiteGroupEndpoint : EndpointBaseAsync
.WithRequest<RemoveSiteGroupRouteRequest>
.WithResult<bool>
{
private readonly IMediator _mediator;
private readonly ILogger<RemoveSiteGroupEndpoint> _logger;
public RemoveSiteGroupEndpoint(IMediator mediator, ILogger<RemoveSiteGroupEndpoint> logger)
{
_mediator = mediator;
_logger = logger;
}
[Authorize(Policy = "Admin")]
[HttpDelete("api/sitegroups/{request}/{groupId}", Name = "remove-sitegroup")]
public override async Task<bool> HandleAsync([FromRoute] RemoveSiteGroupRouteRequest request, CancellationToken cancellationToken = default)
{
try
{
await _mediator.Send(request, cancellationToken);
return true;
}
catch (Exception ex)
{
await _logger.LogError(ex.ToString(), LogLayer.Features, request);
return false;
}
}
}
Program.cs
builder.Services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressInferBindingSourcesForParameters = true;
});
//some code
app.UseRouting();
app.MapControllers();
Client.cs
_httpService comes from Ardalis.APIClient
var devurl = "api/sitegroups/" + request.SitePrefix;
var result = await _httpService.HttpDeleteAsync(devurl);
Thanks!
mw-nfi commented
Problem solved: You should not use the PropertyName "request" or "Request".
But why? is there maybe a bug?
With Kind Regards
Steve Smith commented
Not sure but I assume you'd run into the same issue if you were using a Controller Action instead of an ApiEndpoint. Glad you got it sorted!