[Route("Street/{ZoneID}/{StreetID}/")]
public HttpResponseMessage GetStreet(int ZoneID,int StreetID,[FromUri] RealEstateFilter Filter)
当从客户端发送以下请求时,StreetID始终为0
http://localhost:1887/Street/34/23295?MunZone=7&StartDate=&EndDate=
但它没有任何可选参数
我应该如何配置webapi以便能够阅读[Fromuri]
答案 0 :(得分:6)
使用我的控制器调用Street/34/23295?MunZone=7&StartDate=&EndDate=
定义为:
public class SomeController : ApiController
{
[Route("Street/{ZoneID}/{StreetID}/")]
public HttpResponseMessage GetStreet(int ZoneID, int StreetID, [FromUri] RealEstateFilter Filter)
{
return null;
}
都给:
当我将RealEstateFilter定义为:
时public class RealEstateFilter
{
public int? MunZone { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
}
我的web.api版本是:
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net451" developmentDependency="true" />
我从头开始创建我的Web.Api项目,这是唯一的东西。您是否可能有其他干扰途径?