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
  • 11,885
  • 15
  • 70
  • 96
Zapnologica
  • 21,164
  • 41
  • 147
  • 239
  • 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
  • 227,877
  • 22
  • 326
  • 423
-1

here is an example:

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