【问题标题】:WebApi.HelpPage does not recognize actions with parameters from BindingModelWebApi.HelpPage 无法识别带有 BindingModel 参数的操作
【发布时间】:2016-12-12 22:45:59
【问题描述】:

我在 FieldsController 中定义了以下动作

[HttpGet]
[Route("api/farms/{farmIds}/{harvestYear:int}/fields")]
public IHttpActionResult Get(IntegerListParameter farmIds, int harvestYear)

IntegerListParameter 类是用 ModelBinder 定义的

[ModelBinder(typeof(IntegerListModelBinder))]
public class IntegerListParameter : List<int>
{
}

我的问题是 WebApi.HelpPage 无法识别具有 IntegerListParameter 作为参数的操作。

我正在使用 Microsoft.AspNet.WebApi.HelpPage" version="5.2.3

【问题讨论】:

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


    【解决方案1】:

    我认为模型绑定与 Microsoft.AspNet.WebApi.HelpPage 命名空间无关。它更多关于asp.net WebApi。我不确定为什么需要从 uri 传递参数,而是可以使用 http POST 方法并通过类似于以下内容的主体传递它:

    [Route("api/farms/fields")]
    [HttpPost]
    public HttpResponseMessage Get(IntegerListParameter farmIds, int harvestYear)
    

    但如果你真的想通过URI传递参数,那么你可以在“IntegerListParameter farmIds”之前使用方法/api签名中的[FromUri],或者你可以找到类似的帖子如下:

    How to pass an array of integers to ASP.NET Web API?

    Passing array of integers to webapi Method

    http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多