我试图将共享视图添加到Views/Shared
文件夹,在某些情况下,我需要返回一些纯文本值。这是我的共同看法TextPlainView
:
@model string
@{
Layout = null;
Response.ContentType = "text/plain";
}
@Model
我试图以这种方式从控制器使用它:
public ActionResult GetInfo(bool plain)
{
//Some code to prepare data
string result="Some data";
if (plain)
return View("TextPlainView", result);
else
return View(result);
}
我想在所有控制器上使用此视图,因此我希望将其共享。
我收到此错误:
找不到“ TextPlainView”视图或其主视图,或者没有视图引擎支持搜索到的位置。搜索了以下位置:〜/ Views / Orders / TextPlainView.aspx〜/ Views / Orders / TextPlainView.ascx〜/ Views / Shared / TextPlainView.aspx〜/ Views / Shared / TextPlainView.ascx〜/ Views / Orders / 0。 master〜/ Views / Shared / 0.master〜/ Views / Orders / TextPlainView.cshtml〜/ Views / Orders / TextPlainView.vbhtml〜/ Views / Shared / TextPlainView.cshtml〜/ Views / Shared / TextPlainView.vbhtml〜/ Views / Orders / 0.cshtml〜/ Views / Orders / 0.vbhtml〜/ Views / Shared / 0.cshtml〜/ Views / Shared / 0.vbhtml
如果您想返回纯文本,最好使用ContentResult
。这是专门用于返回原始内容而无需通过视图引擎的操作,默认情况下,其内容类型为text/html
。
有关更多详细信息,请参见https://stackoverflow.com/a/553952/493650。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句