Asp.Net WebAPI和AttributeRouting - 没有重载属性构造函数?

jaf*_*ffa 4 asp.net-web-api attributerouting asp.net-web-api-routing

我刚刚为WebAPI下载了AttributeRouting NuGet包,并且在我的控制器中出现问题.我认为使用它的方法是:

 public class InboxController : ApiController
    {
        private IInboxService _inboxService;

        public InboxController(IInboxService inboxService)
        {
            _inboxService = inboxService;            
        }

        public IEnumerable<MessageModel> GetAll()
        {
            return _inboxService.GetAllMessages();
        }

      [HttpGet("Inbox/Count")]
            public int GetInboxCount()
            {
                return _inboxService.GetMessageCount();
            }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:错误2'System.Web.Http.HttpGetAttribute'不包含带有1个参数的构造函数

我需要快速启动并运行它.有什么理由为什么HttpGet属性没有重载的构造函数?

UPDATE

    [GET("Inbox/EnquiryCount")]
    public EnquiryCountModel GetEnquiryCounts()
    {
        var model = new EnquiryCountModel();
        model.EnquiryCount = _inboxService.GetCustomerEnquiriesCount();
        model.EnquiryResponseCount = _inboxService.GetCustomerEnquiryResponseCount();
        return model;
    }
Run Code Online (Sandbox Code Playgroud)

在路线:

routes.MapHttpRoute("InboxEnquiryApi", "api/inbox/{action}", new { Controller = "Inbox" }, null, new WebApiAuthenticationHandler(GlobalConfiguration.Configuration));
Run Code Online (Sandbox Code Playgroud)

当我点击"api/inbox/EnquiryCount"中的网址时出现此错误:

**No HTTP resource was found that matches the request URI 'http://localhost:49597/api/inbox/enquirycount'**
Run Code Online (Sandbox Code Playgroud)

pat*_*zzi 6

在较新版本的webapi中已更改此语法.[HTTPPOST]现在是独立的,并且路由的新属性恰当地命名为ROUTE,其获取路由URL,例如.

〔路线( "GetRes/{月}")]