在Web Api 的Controller里有两个Action

 public string  Get(string order, int skip, int take)
        {
            
            return "test";
        }
        [Route("GetButtons")]
        [HttpGet]
        public string GetButtons()
        {
            
            return "button";
        }

这是我的请求地址:  http://localhost:51855/Api/BlackCar/GetButo,

明显我的Action名字写错了,但还是能够匹配到 GetButtons(),经过多次测试,只要不带参数,无论Action的名字写成什么,甚至不写Action都是可以匹配到 GetButtons().但是带上3个参数,就可以匹配到Get(string order, int skip, int take).很让我惊讶.这是问题,貌似Route特性不起作用.


最后终于解决了:

经过同事的查看,说我的命名空间引错了.

web api的应该是 using System.Web.Http;

而我引用的是 using System.Web.Mvc;

事情的根源是,我新建Controller的时候选的是这个

27b3ebc72058b4a38155e44433e92d62.png-wh_

真是基础薄弱+粗心啊.



记录一下   ....  呲牙.jpg