ASP.Net MVC 路由问题
我有一个名为 MyArea 的区域,它的注册方式如下:
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 })
我有一个单位控制器,其操作称为单位。请帮忙,我缺少什么?
谢谢!!
I have an area called MyArea and it's registered like so:
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 });
It should work that one property has many units, so I would like my url to look something like this:
http://localhost:50182/myarea/properties/edit/4/units/1
The code i use for the Html.ActionLink looks like:
@Html.ActionLink("Add new Unit", "Unit", "Unit", new { propertyId = 1, unitId = 1 })
I have an Unit controller with an action called Unit. Pleas help, what am i missing?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说“我有一个单位控制器,其动作称为单位。请帮忙,我缺少什么?”
并且您的路由映射当前是...
您希望 MVC 如何知道该路由使用哪个控制器?您需要指定
controller = "Unit"
Update
在您的路由注册中切换顺序
。否则,应该映射到第二条路线的内容将被第一条路线拦截。
You say "I have an Unit controller with an action called Unit. Pleas help, what am i missing?"
and your route mapping is currently ...
How would you expect MVC to know what controller to use for that route? You need to specify
controller = "Unit"
Update
Switch the order of
in your route registration. Otherwise, something that should map to the second route will be intercepted by the first.