2014-02-08 30 views
1

我试图添加一个共享视图到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

+0

试试这个http://www.codeproject.com/Tips/617361/Partial-View-in-ASP-NET-MVC-4 – Ehsan

回答