0

I've got a simple WebAPI app. In my controller I have:

[HttpPost]
public ActionResult DoSomeWork(string stringParam, DTOObject dto)
{
    // Some work gets done in here
}

I've got a console app doing this:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(_context);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var response = client.PostAsJsonAsync("ControllerPath/DoSomeWork", new object[]{someString, dtoObject}).Result;

I don't receive any errors. When my breakpoint is hit inside of the Controller, it shows the string coming in as NULL and the DTO coming is a fully populated but with default values (1/1/1900s, nulls, etc). I feel like the controller isn't properly deserializing the object but I'm kind of at a loss of how to fix this. Any thoughts?

4

1 回答 1

1

解决方案是因为我的控制器不是 ApiController。一旦我将控制器更改为从 ApiController 而不是 Controller 继承,一切正常。

于 2013-02-18T22:42:42.530 回答