Asp.net mvc URL路径为空时的MVC路由

Asp.net mvc URL路径为空时的MVC路由,asp.net-mvc,asp.net-mvc-routing,Asp.net Mvc,Asp.net Mvc Routing,我的控制器中定义了2条路由: [HttpGet] [Route("{customerId}")] public IActionResult GetCustomerOrders(string customerId) { } [HttpGet] [Route("{customerId}/{orderId}")] public IActionResult GetCustomerOrder(string customerId, strin

我的控制器中定义了2条路由:

    [HttpGet]
    [Route("{customerId}")]
    public IActionResult GetCustomerOrders(string customerId)
    {
    }

    [HttpGet]
    [Route("{customerId}/{orderId}")]
    public IActionResult GetCustomerOrder(string customerId, string orderId)
    {
    }
现在,如果有人传入一个url,比如(因此customerId为null);它最终在第一个路由上匹配(在
customerId
参数中使用
orderId
);但我真的很想去2号。我怎样才能使它在第二次登陆时在
customerId
中有一个空值?

两件事。 /api/订单表明您正在使用web api。我猜您希望将此url传达给用户以供浏览。我建议您删除url中的api

[Route("{customerId}")]
应该是

[Route("api/Orders/{customerId}")]
另一个呢

[Route("api/Order/{customerId}/{orderId}")]