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