Answers:
您可以使用ContentResult返回一个纯字符串:
public ActionResult Temp() {
    return Content("Hi there!");
}ContentResult默认情况下返回a text/plain作为其contentType。这是可重载的,因此您还可以执行以下操作:
return Content("<xml>This is poorly formatted xml.</xml>", "text/xml");ContentResult确实if (!String.IsNullOrEmpty(ContentType))设置之前HttpContext.Response.ContentType。我看到的text/html是您的第一个示例,这是现在的默认值,还是由引起的有根据的猜测HttpContext。
                    MediaTypeNames.Text.Plain或,而不是从字面上添加“文本/纯文本”作为字符串MediaTypeNames.Text.Xml。尽管它仅包括一些最常用的MIME类型。(docs.microsoft.com/en-us/dotnet/api/...)
                    如果您知道这是该方法将返回的唯一内容,则也可以只返回字符串。例如:
public string MyActionName() {
  return "Hi there!";
}return用于根据条件发送string或JSON或View的语句,那么我们必须使用它Content来返回字符串。
                    截至2020年,使用ContentResult仍然是上述建议的正确方法,但用法如下:
return new System.Web.Mvc.ContentResult
{
    Content = "Hi there! ☺",
    ContentType = "text/plain; charset=utf-8"
}有两种方法可以将字符串从控制器返回到视图
第一
您只能返回字符串,但不会包含在html文件中,因为字符串将出现在浏览器中
第二 
可以返回一个字符串作为“查看结果”的对象
这是执行此操作的代码示例
public class HomeController : Controller
{
    // GET: Home
    // this will mreturn just string not html
    public string index()
    {
        return "URL to show";
    }
    public ViewResult AutoProperty()
    {   string s = "this is a string ";
        // name of view , object you will pass
         return View("Result", (object)s);
    }
}在运行AutoProperty的视图文件中,它将重定向到Result视图,并发送s
 
代码以查看
<!--this to make this file accept string as model-->
@model string
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Result</title>
</head>
<body>
    <!--this is for represent the string -->
    @Model
</body>
</html>