在Web API 2中返回一个String

0pe*_*tor 6 c# asp.net-web-api asp.net-web-api2

虽然听起来很简单,但我没有找到任何关于此的文档,也许我写错了所以如果是这样的话,一些关于此的好文档将不胜感激.我只想返回一个字符串或类型字符串的模型.

return "string here";
Run Code Online (Sandbox Code Playgroud)

我每次都会收到此错误:

Severity    Code    Description Project File    Line
Error   CS0029  Cannot implicitly convert type 'string' to 'System.Web.Http.IHttpActionResult'  TaskManagement  C:\dev\TaskManagement\TaskManagement\Controllers\JobsController.cs  157
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用CAST - 同样的错误.

return (IHttpActionResult)"string"
Run Code Online (Sandbox Code Playgroud)

Ric*_*Ric 9

你可以这样做,返回200(确定):

public IHttpActionResult Get()
{
    return Ok("some string");
}
Run Code Online (Sandbox Code Playgroud)

看看的文档,看看你可以返回还有什么即:ok,badrequest