【问题标题】:Finding action on wep api 2在 web api 2 上查找操作
【发布时间】:2014-03-27 20:54:52
【问题描述】:

您好,我正在使用 wep api 2 创建此路由。我有

在我的 WebConfigApi 中定义

    config.MapHttpAttributeRoutes();
  //  In Globa.asax
    GlobalConfiguration.Configure(WebApiConfig.Register);

我的方法被装饰成

        [Route("api/pO")]
        [AcceptVerbs("Getpo")]
        [HttpGet]
        public IEnumerable<pOver> Getpo()
        {
           ------
        }

当我使用

运行它时
 ../api/pO/Getpo

我不断收到错误

"<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost:60482/api/pO/Getp0'.</Message><MessageDetail>No action was found on the controller 'prO' that matches the request.</MessageDetail></Error>"

请告诉我如何正确装饰它以运行它。 谢谢

【问题讨论】:

    标签: c# asp.net asp.net-web-api asp.net-web-api2


    【解决方案1】:

    我想你希望它看起来像这样:

     [Route("api/pO/Getpo")]
     [HttpGet]
     public IEnumerable<pOver> Getpo()
     {
            ------
     }
    

    AcceptVerbs 属性旨在执行类似于您在 Action 上放置的 HttpGet 属性的操作。您可以使用 AcceptVerbs("GET") 代替 HttpGet 属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 2013-04-24
      • 2014-11-22
      • 1970-01-01
      • 2014-10-02
      • 1970-01-01
      相关资源
      最近更新 更多