首页 > 解决方案 > 属性路由方法未调用

问题描述

我在 asp.net core web api 中调用带有字符串参数的方法时遇到问题。该方法不会被调用或调用。

** 我的班级看起来像这样 **

[Route("api/[controller]")]
[ApiController]
public class MyClass : ControllerBase
{
    [HttpGet("dispatch_discrepancies/{airwayBillNumber}")]
    public List<Discrepancy> GetDispatchDiscrepancies(string airwayBillNumber)
        {
                ....
        }
    }

下面是我的路线配置。

app.UseMvc(routes => {
    routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");
});

标签: asp.net-coreasp.net-web-apiattributerouting

解决方案


推荐阅读