2011-03-29 7 views
1

나는 지역이 MyArea라고하고이과 같이 등록되어 :ASP.Net MVC 경로 문제

context.MapRoute(null, "MyArea", new { controller = "MyAreaController", action = "Index" }); 

//Properties 
context.MapRoute(null, "MyArea/properties", new { controller = "Property", action = "Index" }); 
context.MapRoute(null, "MyArea/properties/edit/{propertyId}", new { controller = "Property", action = "Property" }); 

//Units 
context.MapRoute(null, "MyArea/properties/edit/{propertyId}/units/{unitId}", new { action = "Unit", propertyId = 1, unitId = 1 }); 

그것은 하나 개의 속성이 많은 유닛을 가지고 일을해야한다, 그래서 나는이 같은 것을보고 내 URL을 싶습니다

http://localhost:50182/myarea/properties/edit/4/units/1

내가 Html.ActionLink에 사용하는 코드는 외모와 같은 :

@Html.ActionLink("Add new Unit", "Unit", "Unit", new { propertyId = 1, unitId = 1 }) 

유닛이라는 액션이있는 유닛 컨트롤러가 있습니다. 내가 도와 줄 수있는 것이 무엇입니까?

감사합니다.

+0

어떤 문제가 있습니까? –

+0

링크가 http : // localhost : 50182/myarea/properties/edit/4/units? controller = 속성 및 길이 = 4 이 아닌 http : // localhost : 50182/myarea/properties/edit/4로 이동합니다./units/1 다음과 같은 오류 메시지가 표시됩니다. 값을 null 또는 비워 둘 수 없습니다. 매개 변수 이름 : controllerName – Pete

답변

1

당신은 "유닛이라는 액션이있는 유닛 컨트롤러가 있습니다. 무엇을 놓치셨습니까?"라고 말합니다.

및 경로 매핑은 현재 ...

context.MapRoute(null, "MyArea/properties/edit/{propertyId}/units/{unitId}", new { action = "Unit", propertyId = 1, unitId = 1 }); 

당신은 어떻게 MVC 그 경로에 사용할 것을 컨트롤러 알고 기대? 당신은 당신의 경로 등록에 controller = "Unit"

업데이트

스위치를

context.MapRoute(null, "MyArea/properties/edit/{propertyId}", new { controller = "Property", action = "Property" }); 

    //Units 
    context.MapRoute(null, "MyArea/properties/edit/{propertyId}/units/{unitId}", new { action = "Unit", propertyId = 1, unitId = 1 }); 

의 순서를 지정해야합니다. 그렇지 않으면 두 번째 경로에 매핑해야하는 항목이 첫 번째 경로에 의해 차단됩니다.

+0

URL을 시도했지만 URL은 다음으로 이동합니다. http : // localhost : 50182/myarea/properties/edit/ – Pete

+0

업데이트를 확인하십시오. – smartcaveman

+0

주위를 돌았지만이 URL은 localhost : 50182/myarea/properties/ – Pete