Reputation: 4302
What is the equivalent of
var newOrder = new OrderViewModel()
{
Id = orderDetails.Id,
Name = orderDetails.Service.Name,
.....
};
Request.CreateResponse(HttpStatusCode.OK, newOrder);
In this format:
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = "successfully created blablabla";
In the Request.CreateResponse()
I can pass an object. How can I do that with HttpResponseMessage
?
Want to be able to pass a message (like ReasonPhrase
) as well, but can't do that with Request.CreateResponse()
. Or I'm missing something.
Upvotes: 1
Views: 3956
Reputation: 4063
To pass in an object as response content you can construct ObjectContent<T>
:
response.Content = new ObjectContent<OrderViewModel>(newOrder,
new JsonMediaTypeFormatter())
Other constructors of ObjectContent
:
http://msdn.microsoft.com/en-us/library/hh835040(v=vs.118).aspx
Upvotes: 2