2014-02-08 4 views
1

어떤 경우에는 일부 일반 텍스트 값을 반환해야하는 Views/Shared 폴더에 공유보기를 추가하려고했습니다.ASP.NET MVC 4에서 공유보기 사용

@model string 
@{ 
    Layout = null; 
    Response.ContentType = "text/plain"; 
} 
@Model 

내가 컨트롤러에서이 방법을 사용하려 : 여기 내 공유보기 TextPlainView이다 나는 모든 컨트롤러에 걸쳐이보기를 사용하려면

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

답변

2

당신이 ContentResult를 사용하는 것이 아마 더 좋을 것이다 일반 텍스트를 반환 할 경우

나는이 오류가 발생했습니다. 이것은 뷰 엔진을 거치지 않고 원시 컨텐트를 반환하기위한 것이며, 기본적으로 콘텐츠 유형은 text/html입니다.

자세한 내용은 https://stackoverflow.com/a/553952/493650을 참조하십시오.

관련 문제