ASP.NET 웹 양식 응용 프로그램을 ASP.NET MVC 3으로 마이그레이션하고 있습니다. 라우팅에 대해 이해하고 있지만 이해가되지 않습니다. 내 응용 프로그램에서는 세 개의 .cshtml 파일을/internal/products/find /에있는 디렉토리에 만들었습니다. 데모 용으로 .cshtml 파일의 이름은 "view1.cshtml", "view2.cshtml"및 "view3.cshtml"입니다.ASP.NET MVC 3 - 경로 설정
"InternalController"라는 컨트롤러가 있습니다. 내 목표는/내부 경로 안의 모든 위치에 대해 InternalController를 사용하는 것입니다. 내가하려는 일이 허용되는지 확실하지 않습니다. 나는 그것이 있다고 생각한다. 어느 쪽이든,이 시간에, 나는 InternalController에서 다음이 내 global.asax.cs 파일에서
public ActionResult View1()
{
return View();
}
public ActionResult View2()
{
return View();
}
public ActionResult View3()
{
return View();
}
을, 나는 다음과 같이 이러한 전망에 경로를 등록하기 위해 노력하고있어 :
routes.MapRoute(
"View1",
"{controller}/products/find/view1",
new { controller = "Internal", action = "View1" }
);
routes.MapRoute(
"View2",
"{controller}/products/find/view2",
new { controller = "Internal", action = "View2" }
);
routes.MapRoute(
"View3",
"{controller}/products/find/view3",
new { controller = "Internal", action = "View3" }
);
내 브라우저에서/internal/products/find/view1을 방문하려고하면 ASP.NET 오류 화면이 표시되고 다음과 같이 표시됩니다.
보기 'View1'또는 해당 마스터를 찾을 수 없거나 뷰 엔진이 없습니다 검색된 위치를 지원합니다. ~/Views/internal/View1.aspx ~/Views/internal/View1.ascx ~/Views/Shared/View1.aspx ~/Views/Shared/View1.ascx ~/Views 다음 위치를 검색했습니다. /dashboard/View1.cshtml ~/조회/대시 보드/View1.vbhtml ~/조회/공유/View1.cshtml ~/조회/공유/View1.vbhtml 내가 잘못 뭐하는 거지
?/internal/products/find/view1 경로가 가장 중요합니다. 이상적으로, 나는 매번 InternalController에서이를 노출하고 싶습니다. 그러나 나는 그것에 거친 것을 가지고있다. 내가 도대체 뭘 잘못하고있는 겁니까?
감사합니다.
http://mysite.com/blahblah/products/find/blahblahview
는 컨트롤러 blahblahview 내부 작업을 뷰 1을 활성화합니다 : 당신이
routes.MapRoute(
"View1",
"{controller}/products/find/{action}",
new { controller = "Internal", action = "View1" }
);
을 쓸 때
내 .cshtml 파일은/products/find 디렉토리에 있습니다. 해당 뷰를 사용하기 위해 컨트롤러 또는 라우트를 어떻게 업데이트합니까? –
나는 그것을하지 않을 것이다 (당신의 파일을 기본 뷰 폴더에 복사한다.), 정말로 그것을하고 싶다면 여기에 답이있다 : http://stackoverflow.com/questions/909794/how-to-change- default-view-location-scheme-in-asp-net-mvc –