2016-07-30 6 views
2

Visual Studio에서 웹 API 프로젝트를 만들었습니다. 속성 라우팅을 사용하고 있습니다. 여기 컨트롤러 폴더 아래의 컨트롤러는 다음과 같습니다ASP.NET보기를 찾을 수 없음

public class RegistrationController : Controller 
{ 
    // GET: Registration 
    [Route("")] 
    public ActionResult CreateUser(string platform) 
    { 

     return View("~/Views/Registration/CreateUser.cshtml", platform); 
    } 
} 

나는 URL 작동 http://localhost/application하지만 난 URL http://localhost/application?platform=android하여 쿼리 문자열 매개 변수를 전달하려고 할 때, 그것은 다음과 같은 오류 제공함으로써 CreateUser 작업을 호출 할 때 :

The view '~/Views/Registration/CreateUser.cshtml' or its master was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Registration/CreateUser.cshtml

~/Views/Registration/android.master

~/Views/Shared/android.master

~/Views/Registration/android.cshtml

~/Views/Registration/android.vbhtml

~/Views/Shared/android.cshtml

~/Views/Shared/android.vbhtml

내가보기에 왜보기를 찾을 수 없는지 또는 왜 조회 문자열 매개 변수의 이름으로보기를 찾으려고하는지 이해할 수 없습니다.

+0

이 코드는 작동합니다 예상대로 작동합니다

public class RegistrationController : Controller { // GET: Registration [Route("")] public ActionResult CreateUser(string platform) { return View("~/Views/Registration/CreateUser.cshtml", model: platform); } } 

.... 컴파일러는 당신이 전화를위한 방법에 과부하를 알 수 있도록함으로써 혼란을 피할 것이다 명명 된 인수를 사용하여이 문제를 해결할 수 있습니다 벌금. 보기 파일이 프로젝트/솔루션에 포함되어 있습니까? – Shyju

+0

반환보기에서보기의 전체 경로가 필요 없습니다. 또한 위에 왜 빈 경로 데코레이터가 있습니까? – thsorens

+0

전체 경로가 필요하지는 않지만 아무것도 중단되지 않습니다. 여전히 작동해야합니다. 빈 경로는이 작업을 기본값으로 만드는 것입니다. – Shyju

답변

4

아마도이보기를 찾을 수 있습니다. 찾을 수없는 마스터 페이지입니다. 당신은 단서가 뷰에 대한 검색 매개 변수 값을 포함한다는 사실이었다

Creates a System.Web.Mvc.ViewResult object using the view name and master-page name that renders a view to the response.

class Controller : ... { 
    ViewResult View(string viewName, string masterName); 
} 

과부하 방법을 사용하고 있기 때문에입니다

. 플랫폼 매개 변수를 전달한 문자열이 문자열이기 때문에 string viewNamestring masterName 매개 변수를 사용하는 메서드와 일치하는 메서드와 일치했습니다.

ControllerViewResult View() 방법에 대해 많은 과부하가 있습니다. 이 경우 platform을 개체 모델로 전달하려고했을 것입니다. 당신은 거기에서 모든

+0

매력처럼 작동했습니다. 감사합니다. –