2011-03-29 85 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 }); 

它应该是一个酒店有很多单位,所以我想我的网址看起来是这样的:

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

我使用的Html.ActionLink的代码如下所示:

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

我有一个单位控制器与一个称为单位的行动。请帮助,我错过了什么?

谢谢!

+0

你面临什么问题? – 2011-03-29 13:46:59

+0

链接转到http:// localhost:50182/myarea/properties/edit/4/units?controller = Property&Length = 4 而不是: http:// localhost:50182/myarea/properties/edit/4/units/1 我收到以下错误消息: 值不能为空或为空。 参数名称:controllerName – Pete 2011-03-29 13:50:19

回答

1

你说:“我有一个单位控制器,带有一个名为Unit的动作。请帮忙,我错过了什么?”

和你的路由映射是目前...

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

我确实尝试过,但网址是: http:// localhost:50182/myarea/properties/edit/ – Pete 2011-03-29 13:59:43

+0

检查更新。 – smartcaveman 2011-03-29 14:07:48

+0

把它翻了个遍,但是这个URL到localhost:50182/myarea/properties /编辑 – Pete 2011-03-29 14:21:55