我試圖添加一個共享視圖到Views/Shared
文件夾,我需要在某些情況下返回一些純文本值。這裏是我的共享視圖TextPlainView
:在ASP.NET MVC 4中使用共享視圖
@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);
}
我想在所有的控制器使用這個觀點,所以我希望它被共享。
我得到這個錯誤:
The view 'TextPlainView' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/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
試試這個http://www.codeproject.com/Tips/617361/Partial-View-in-ASP-NET-MVC-4 – Ehsan