This simplest method is to use the helpers from the base Controller class.
public ActionResult ExampleNotFound()
{
return NotFound("Sorry !!");
}
public ActionResult ExampleOk()
{
return Ok("Congratulations !!");
}
Alternatively you can return a new ContentResult
and set it's status code.
return new ContentResult
{
Content = "Congratulations !!",
ContentType = "text/plain",
StatusCode = 200
};
These two methods are slightly different, the ContentResult
will always have a ContentType
of text/plain
The Ok()
and NotFound()
methods return an ObjectResult
which uses a formatter to serialize your string according to the content types in the Accept header from the request.