2012-02-20 5 views
0

저는 ASP.NET MVC 응용 프로그램을 만들고 있습니다. 웬일인지, 나는 내가 라우팅을 이해한다고 생각할 때마다, 내가 이해하지 못하는 것이 튀어 나온다. 현재, 나는 알아낼 수없는 두 가지 경로를 가지고 있습니다. 내 디렉토리 구조 내 global.asax.cs 파일에서MVC 라우팅 오해

- Views 
    - Internal 
    - Profile 
     - Index.cshtml 
    - Input 
     - Page1.cshtml 

다음, 나는 다음과 같은 매핑을 추가 한 다음과 같습니다 MyController에에서

routes.MapRoute(
    "UserProfileInfo", 
    "{controller}/profile", 
    new { controller = "Internal", action = "UserProfileInfo" } 
); 


    routes.MapRoute(
    "Page1", 
    "{controller}/input/page1", 
    new { controller = "Internal", action = "Page1" } 
); 

을, 나는 다음과 같은 한 :

public ActionResult UserProfileInfo() 
    { 
    return View("~/Views/internal/profile/Index.cshtml"); 
    } 

    public ActionResult Page1() 
    { 
    return View("~/Views/internal/input/Page1.cshtml"); 
    } 

내 컨트롤러를 하나의 컨트롤러에 저장하고 싶습니다. 나는 내가 모든 것을 올바르게 설정했다고 생각했다. 그러나 나는 404를 계속 얻는다. 내가 뭘 잘못하고 있니?

+0

어떤 URL이 404를 제공합니까? – Simon

+0

http : // localhost : [port]/internal/input/page1 또는 http : // localhost : [port]/profile/info에서 펀치를하면 404가됩니다. http : // localhost를 입력하면 알아 챘습니다. : [port]/internal/UserProfileInfo 내 페이지가 나타납니다. 하지만, 내가 쓰고 싶은 URL이 아닙니다. –

+0

먼저 기존 기본 경로를 제거해야 할 수도 있습니다.이 경로는 먼저 일치 할 수 있습니다. – Simon

답변

0

InternalController이라는 클래스에 매핑을 만들려면 MapRoute 호출에서 컨트롤러 이름의 "컨트롤러"접미사를 제거하십시오. Controller 접미사는 일치하는 구현을 찾을 때 프레임 워크에 의해 추가됩니다. 예 :

routes.MapRoute( 
    "UserProfileInfo", 
    "{controller}/profile", 
    new { controller = "Internal", action = "UserProfileInfo" } 
); 
+0

에 추가 된 {controller}/{action}/{id} 경로는 실제 코드에 없습니다. 이 지저귀다. 게시물을 업데이트했습니다. 비록 이것을 지적 해 주셔서 감사합니다. –