Asp.Net WebAPI and AttributeRouting - no overloaded attribute constructor?

I just downloaded the AttributeRouting NuGet package for WebAPI and ran into a problem in my controller. I thought that using this was to have something like:

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(); } } 

However, I get the following error: Error 2 'System.Web.Http.HttpGetAttribute' does not contain a constructor that takes 1 argument

I need to do this quickly and quickly. Is there a reason why the HttpGet attribute does not have an overloaded constructor?

UPDATE

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

In routes:

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

When I click the url in 'api / inbox / InquiryCount', I get this error:

 **No HTTP resource was found that matches the request URI 'http://localhost:49597/api/inbox/enquirycount'** 
+4
source share
2 answers
+6
source

This syntax has been changed in newer versions of webapi. [HTTPPOST] is now standalone, and there is a new route attribute for the route. A ROUTE that takes a URL route for example.

[Route ("GetRes / {month}")]

+4
source

Source: https://habr.com/ru/post/1479858/


All Articles