0

How can I return a statuscode and data in a Asp.net web api action method?

I currently just have the status code:

[HttpGet]
public HttpResponseMessage Status(string id)
{              
    var msg2 = Request.CreateResponse(HttpStatusCode.OK);               
    return msg2;          
}
Max
  • 12,622
  • 16
  • 73
  • 101
Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • 1
    Did you even bother to google it? http://stackoverflow.com/questions/12240713/put-content-in-httpresponsemessage-object – Thomas Mar 12 '14 at 10:12

2 Answers2

0

Assuming that you're on the most up to date version, you can just have:

public IHttpActionResult Status(string id)
{           
    return Content(HttpStatusCode.OK,myDataFromSomewhere);
}

See Content

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
-1

here is an example:

string response = "blabla"
return Request.CreateResponse(HttpStatusCode.OK, response);
DmitryK
  • 1,333
  • 1
  • 11
  • 18