C# 在ASP.NET MVC 4中使用共享视图
我试图将共享视图添加到C# 在ASP.NET MVC 4中使用共享视图,c#,asp.net-mvc,asp.net-mvc-4,shared,C#,Asp.net Mvc,Asp.net Mvc 4,Shared,我试图将共享视图添加到Views/shared文件夹,在某些情况下需要返回一些纯文本值。这是我的共享视图textplaneview: @model string @{ Layout = null; Response.ContentType = "text/plain"; } @Model 我试着从控制器上这样使用它: public ActionResult GetInfo(bool plain) { //Some code to prepare data str
Views/shared
文件夹,在某些情况下需要返回一些纯文本值。这是我的共享视图textplaneview
:
@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/textplaneview.aspx
~/Views/Orders/textplaneview.ascx
~/Views/Shared/textplaneview.aspx
~/Views/Shared/textplaneview.ascx
~/Views/Orders/0.master
~/Views/Shared/0.master
~/Views/Orders/textplaneview.cshtml
~/Views/Orders/textplaneview.vbhtml
~/Views/Shared/textplaneview.cshtml
~/Views/Shared/textplaneview.vbhtml
~/Views/Orders/0.cshtml
~/Views/Orders/0.vbhtml
~/Views/Shared/0.cshtml
~/Views/Shared/0.vbhtml
如果您想返回纯文本,最好使用。这专门用于返回原始内容而不经过视图引擎,默认情况下,它的内容类型为
text/html
有关详细信息,请参阅。试试这个