在Web API 2中返回字符串 [英] Return a String in Web API 2
本文介绍了在Web API 2中返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
听起来很简单,我没有找到任何有关此文档的信息,也许我用错了措辞,因此,如果这样的话,不胜感激的一些文档将不胜感激.我只想返回一个字符串或字符串类型的模型.
As simple as it sounds, I haven't found any documentation on this and perhaps I'm wording it wrong so if so, some good documentation on this would be appreciated. I simply want to return a string or a model of type string.
return "string here";
我每次都会收到此错误:
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
我也尝试过使用CAST-同样的错误.
return (IHttpActionResult)"string"
推荐答案
您可以执行此操作以返回200(确定):
you can do this which returns a 200 (Ok) :
public IHttpActionResult Get()
{
return Ok("some string");
}
Take a look at the docs to see what else you can return ie: ok
, badrequest
etc
这篇关于在Web API 2中返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文