web api Route特性(注解)不起作用
在Web Api 的Controller里有两个Action
publicstringGet(stringorder,intskip,inttake){return"test";}
[Route("GetButtons")][HttpGet]publicstringGetButtons(){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的时候选的是这个
真是基础薄弱+粗心啊.
记录一下 .... 呲牙.jpg
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。