C# ASP.NET核心:匹配路由,一个带主体,一个不带主体

C# ASP.NET核心:匹配路由,一个带主体,一个不带主体,c#,asp.net-core,asp.net-core-webapi,C#,Asp.net Core,Asp.net Core Webapi,我有一条DELETE路线,如下所示: [HttpDelete("{id}")] public async Task<StatusCodeResult> DeleteService(string id) { return await _repo.DeleteServiceAsync(id); } [HttpDelete("{id}")] public async Task<StatusCodeResult> DeleteService([FromBody] Ser

我有一条
DELETE
路线,如下所示:

[HttpDelete("{id}")]
public async Task<StatusCodeResult> DeleteService(string id)
{
    return await _repo.DeleteServiceAsync(id);
}
[HttpDelete("{id}")]
public async Task<StatusCodeResult> DeleteService([FromBody] ServiceEntity service, string id)
{
    if(service == null)
        return await _repo.DeleteServiceAsync(id);
    else
        return await _repo.DeleteServiceWithEntityAsync(id, service);
}
然而,这不起作用,因为,我不想设置为真;在每一个其他路由/端点中,都需要默认行为,
AllowEmptyInputInBodyModelBinding==false

我可以有两条不同的路线,一条带body参数,另一条不带body参数,但这会生成匹配的路线,并且不会命中任何端点:

[HttpDelete("{id}")]
public async Task<StatusCodeResult> DeleteService(string id)
{
    return await _repo.DeleteServiceAsync(id);
}

[HttpDelete("{id}")]
public async Task<StatusCodeResult> DeleteServiceWithEntity([FromBody] ServiceEntity service, string id)
{
    return await _repo.DeleteServiceWithEntityAsync(id, service);
}
[HttpDelete(“{id}”)]
公共异步任务删除服务(字符串id)
{
返回等待_repo.DeleteServiceAsync(id);
}
[HttpDelete(“{id}”)]
公共异步任务DeleteServiceWithEntity([FromBody]ServiceEntity服务,字符串id)
{
return wait _repo.DeleteServiceWithEntityAsync(id,service);
}

获得我想要的行为的最佳方式是什么?我无法添加单独的端点,因为我需要与现有API保持一致。

我认为这是不可能的。还有这样的“过载”造成误解,究竟用什么方法做。对我来说,更好的解决方案是使用另一种方法删除实体,我同意,但我无法更改规范。原始API是使用ASP.NET(而不是Core)编写的,它允许空参数。我可能不得不咬紧牙关,将AllowEmptyInputInBodyModelBinding设置为真,但我对另一个解决方案抱有希望。我对此有一些想法,但在考虑发布答案之前,我需要问几个问题。1:如果你不提供尸体,你会得到415的回应吗?和2:您是否确认将
允许mptyInputInbodyModelBinding
设置为
true
实际上有效?