我新建Controller的时候选的是这个 真是基础薄弱+粗心啊. 记录一下 .... 呲牙.jpg

时间:2022-04-30 08:24:09

标签:web api route 特性

在Web Api 的Controller里有两个Action

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

这是我的请求地点:  :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的时候选的是这个

我新建Controller的时候选的是这个 真是基础薄弱+粗心啊. 记录一下 .... 呲牙.jpg

真是根本单薄+粗心啊.



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