web api Route特性(注解)不起做用

在Web Api 的Controller里有两个Actionweb

 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,c#

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


最后终于解决了:ide

通过同事的查看,说个人命名空间引错了.测试

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

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

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

27b3ebc72058b4a38155e44433e92d62.png-wh_

真是基础薄弱+粗心啊.string



记录一下   ....  呲牙.jpgit

相关文章
相关标签/搜索