Yasir
Yasir

Reputation: 1625

Parameter binding in WebApi post method

I am unable to bind data to the locationModel parameter in the following method. I looked at other posts but no solution seems to be working:

// Web Api Post method

public HttpResponseMessage Post(string vin, [FromBody] LocationModel locationModel)
{
    return null;
}

I am invoking the method through fiddler in the following manner:

enter image description here

The method is called upon executing the post request but the LocationModel is null. Here is the definition for the LocationModel:

public class LocationModel
{
    public string Url { get; set; }

    public DateTime LogTimestamp { get; set; }

    public float Latitude { get; set; }

    public float Longitude { get; set; }

    public decimal OdometerReading { get; set; }

    public DateTime LastUpdatedTimestamp { get; set; }

    public string Source { get; set; }
}

What am I doing wrong?

Upvotes: 0

Views: 653

Answers (1)

petelids
petelids

Reputation: 12815

Your JSON is slightly malformed - you have

"Url" = "http://localhost...", 

rather than

"Url" : "http://localhost...",

i.e. you have = instead of :

Upvotes: 1

Related Questions