1
   [Route("Street/{ZoneID}/{StreetID}/")]
    public HttpResponseMessage GetStreet(int ZoneID,int StreetID,[FromUri]       RealEstateFilter Filter)

StreetID Is Always 0 when Following Request Is Being Sent From Client

http://localhost:1887/Street/34/23295?MunZone=7&StartDate=&EndDate=

but it works without any optional parameter

http://localhost:1887/Street/34/23295

how should i configure webapi to be able to read [Fromuri]

2
  • i also tried [Route("Street/{ZoneID}/{StreetID}")] Commented Jan 24, 2016 at 10:13
  • Can you post a mcve ? This is working OK for me, I've made some assumptions about RealEstateFilter which I've posted below. Thanks. Commented Jan 24, 2016 at 22:50

1 Answer 1

7

Calling Street/34/23295?MunZone=7&StartDate=&EndDate= with my Controller Defined as:

public class SomeController : ApiController
{
    [Route("Street/{ZoneID}/{StreetID}/")]
    public HttpResponseMessage GetStreet(int ZoneID, int StreetID, [FromUri] RealEstateFilter Filter)
    {
        return null;
    }

Gave:

enter image description here

When I defined RealEstateFilter as:

public class RealEstateFilter
{
    public int? MunZone { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
}

My web.api version is:

  <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" />

I created my Web.Api project from scratch, and this is the only thing in it. Is it possible you have some other route that is interfering?

Sign up to request clarification or add additional context in comments.

3 Comments

<package id="Microsoft.AspNet.WebApi" version="5.2.2" targetFramework="net45" /> not interfering with other route because it hits the breakpoint in controller.
Can you share a more complete example. e.g. on github?
Thank you NikolaiDante . i found the problem , the query String had a parameter StreetID at end of string so it was Always binding to StreetID in route rather than StreetID in url.my query string was Street/34/23295?MunZone=7&StartDate=&EndDate=&StreetID=, i removed StreetID form querystring. sorry to take your time and thanks for your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.