Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have following model classes in my project:

public class RiskInfo
{
    /// <summary>
    /// Gets or sets the risk id.
    /// </summary>
    public string RiskId { get; set; }

    /// <summary>
    /// Gets or sets the risk address.
    /// </summary>
    public PropertyAddress RiskAddress { get; set; }
}

public class PropertyAddress
{
    /// <summary>
    /// Gets or sets the street number.
    /// </summary>
    public string StreetNumber { get; set; }

    /// <summary>
    /// Gets or sets the name of the street.
    /// </summary>
    public string StreetName { get; set; }

    /// <summary>
    /// Gets or sets the city.
    /// </summary>
    public string City { get; set; }

    /// <summary>
    /// Gets or sets the county.
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// Gets or sets the state.
    /// </summary>
    public string State { get; set; }
}

I have an action method in my controller that is defined like:

    [GET("hydrantflow/riskinfo")]
    public HttpResponseMessage GetFlowTestByRiskInfo([FromUri]RiskInfo riskInfo)

I am trying to call this action method from Fiddler by using this URL:

http://localhost:63932/hydrantflow/riskinfo?riskid=49WY99000191&streetnumber=900&streetname=pine%20st&city=pinedale&state=wy

but when I debug my action method, I see that only riskInfo.RiskId property is populated, riskInfo.RiskAddress stays null. However, if I change the above URL to

http://localhost:63932/hydrantflow/riskinfo?riskid=49WY99000191&riskaddress.streetnumber=900&streetname=pine%20st&city=pinedale&state=wy

I see that the riskInfo.RiskAddress.StreetNumber is now 900. It seems like I need prefix all the parameters in my URL with the property name "riskaddress" that doesn't seem like the best way to do this.

Is there a better to use parameter binding with nested objects?

Thanks

share|improve this question
1  
You could create a custom parameter binding(ex: deriving from HttpParameterBinding) to handle this yourself...but even if you do so i am wondering how would you differentiate between top level properties vs. nested properties..there has to be some kind of logic in differentiating them... –  Kiran Challa Dec 20 '13 at 16:03
 
Are you sure you want to post an object to a GET method ? –  Shyju Dec 20 '13 at 16:10
 
@Shyju: Yes, I don't want to use body for sending parameters while makign a GET call. Although, HTTP doesn't prevent you from doing it, its not usually recommended. –  manu79 Dec 20 '13 at 16:21
 
@Kiran: Yes, I read about HttpParameterBinding but wasn't sure if there is some solution out of the box. –  manu79 Dec 20 '13 at 16:21
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.