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
내가보기에 왜보기를 찾을 수 없는지 또는 왜 조회 문자열 매개 변수의 이름으로보기를 찾으려고하는지 이해할 수 없습니다.
이 코드는 작동합니다 예상대로 작동합니다
.... 컴파일러는 당신이 전화를위한 방법에 과부하를 알 수 있도록함으로써 혼란을 피할 것이다 명명 된 인수를 사용하여이 문제를 해결할 수 있습니다 벌금. 보기 파일이 프로젝트/솔루션에 포함되어 있습니까? – Shyju
반환보기에서보기의 전체 경로가 필요 없습니다. 또한 위에 왜 빈 경로 데코레이터가 있습니까? – thsorens
전체 경로가 필요하지는 않지만 아무것도 중단되지 않습니다. 여전히 작동해야합니다. 빈 경로는이 작업을 기본값으로 만드는 것입니다. – Shyju