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'**
source share