2010-02-26 2 views
1

나는이 일을하는 SWORN을 가질 수 있었지만, 어딘가에 선을 따라 분명히 그것을 깨뜨렸다. 아마 VS2008의 ASP.NET MVC에서 VS2010의 ASP.NET MVC2로 마이 그 레이션하는 동안이었을 것입니다.이 ASP.NET MVC2 RC ActionLink가 작동하도록 도와 주시겠습니까?

내 ActionLink :

Html.ActionLink(segment.TitleWithChapterNumber, "Index", "Read", new { bookCode = Model.Product.Id, segmentCode = segment.Index }, null) 

나는 그것이 일치 할 것으로 예상 경로는 : 나는 그것이 클릭 http://localhost/Obr/Read/14/0 같이 할 http://localhost/Obr/Read?bookCode=14&segmentCode=0 그러나 :

routes.MapRoute(
    "Read", 
    "Read/{bookCode}/{segmentCode}/{sectionCode}/{renderStrategy}", 
    new { controller = "Read", action = "Index", bookCode = "", segmentCode = "", sectionCode = "", renderStrategy = "" } 
); 

이처럼 보이는 링크를 렌더링 링크를 렌더링하면 올바른 컨트롤러로 이동하게되고 응답이 정확합니다. 링크를 붙여 넣으면 모양이 좋아 보이지만 제대로 작동합니다. 일치하는 것 같아요?

나는 분명한 뭔가를 놓치고 있습니까? 나는 너무 오랫동안 내가 뭘 더 이상 찾고 있는지조차 몰랐다.

참고로, 여기 내 노선 모두 :

액션 서명은 다음과 같습니다
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

routes.MapRoute(
    "ReadImage", 
    "Read/Image/{bookId}/{imageName}", 
    new { controller = "Read", action = "Image" } 
); 

routes.MapRoute(
    "Read", 
    "Read/{bookCode}/{segmentCode}/{sectionCode}/{renderStrategy}", 
    new { controller = "Read", action = "Index", bookCode = "", segmentCode = "", sectionCode = "", renderStrategy = "" } 
); 

routes.MapRoute(
    "BookReport", 
    "BookReport/{action}/{folder}", 
    new { controller = "BookReport", action = "Details", folder = "" } 
); 

routes.MapRoute(
    "Reference", 
    "Reference/Details/{referenceType}/{searchText}", 
    new { controller = "Reference", action = "Details", referenceType = "", searchText = "" } 
); 

routes.MapRoute(
    "PaginatedAudits",          // Route name 
    "Audit/Page/{pageNumber}",        // URL with parameters 
    new { controller = "Audit", action = "Index" }   // Parameter defaults 
); 

routes.MapRoute(
    "PaginatedReadLog",          // Route name 
    "ReadLog/Page/{pageNumber}",       // URL with parameters 
    new { controller = "ReadLog", action = "Index" }  // Parameter defaults 
); 

routes.MapRoute(
    "Default",            // Route name 
    "{controller}/{action}/{id}",       // URL with parameters 
    new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
); 

:

[Authorize] 
public ActionResult Index(string bookCode, string segmentCode, string sectionCode, string renderStrategy) 
{ 
    // code 
} 
+0

다른 경로를 따라 잡아야합니다. ReadController로 향하는 다른 경로가 있습니까? –

+0

좋은 질문입니다. 내 전체 RegisterRoutes 본문을 추가했습니다. – Chris

+0

당신의 행동은 어떻게 생겼습니까? – Odd

답변

0

명시 적 경로의 이름을 지정하여 경로 링크를 시도하십시오 :

Html.RouteLink(
    segment.TitleWithChapterNumber, // linkText 
    "Read", // routeName 
    new { 
     bookCode = Model.Product.Id, 
     segmentCode = segment.Index 
    }, // routeValues 
    null // htmlAttributes 
) 
+0

어떤 이유로 인해 나는 이미 http : // localhost/Obr/Library/Details/14가 된 페이지에 링크 된 앵커를 생성했습니다 – Chris

0

경로 정의에 빈 문자열 대신 UrlParameter.Optional이 있어야합니다.

routes.MapRoute(
    "Read", 
    "Read/{bookCode}/{segmentCode}/{sectionCode}/{renderStrategy}", 
    new { controller = "Read", action = "Index", bookCode = UrlParameter.Optional, segmentCode = UrlParameter.Optional, sectionCode = UrlParameter.Optional, renderStrategy = UrlParameter.Optional } 
); 

이것은 MVC 확장을 통해 생성 된 컨트롤러 및 양식 URL의 리디렉션에도 도움이됩니다.

관련 문제