简体   繁体   English

ASP.Net MVC对嵌套资源的支持?

[英]ASP.Net MVC support for Nested Resources?

I'm looking for a routing option similar to the nested RESTFul routes functionality available through Rails. 我正在寻找类似于Rails提供的嵌套RESTFul路由功能的路由选项。 The SimplyRestful project on MvcContrib doesn't appear to be active any longer nor does it appear to be current with the 1.0 MVC release. MvcContrib上的SimplyRestful项目似乎不再是活动的,也不是1.0 MVC版本的最新版本。

This is the uri scheme I'm looking for, 这是我正在寻找的uri计划,

/Activity/10/Task/1/Edit or /Activity/10/Task/Edit/1 / Activity / 10 / Task / 1 / Edit或/ Activity / 10 / Task / Edit / 1

I simply haven't been able to get it to work and all the documentation I've run across describes the non-nested scenario. 我根本无法让它工作,我遇到的所有文档都描述了非嵌套方案。 It doesn't seem like it'd be that difficult.... 它似乎并不那么困难......

This is what I've been working with... 这就是我一直在努力的...

routes.MapRoute(null,
        "Activity/{activityId}/Task/{action}/{id}", 
        new { controller = "Task", action = "Edit", activityId = "", id = "" });

Add a default value for activity : activity添加默认值:

routes.MapRoute(null,
    "Activity/{activityId}/Task/{action}/{id}/{activity}",
    new { 
        controller = "Task", 
        action = "Edit", 
        id = "",
        activityId = "", 
        activity = "" });

Remember also that this route will only pick up urls on the form 还要记住,这条路线只会在表格上提取网址

/Activity/10/Edit/1/theActivity

while your example 而你的榜样

/Activity/10/Edit/1

will be picked up by the default route, setting the route values to 将通过默认路线拾取,将路线值设置为

controller = "Activity"
action = "10"
id = "Edit/1"

Phil Haack's Routing Debugger for ASP.NET MVC is extremely useful for figuring out how to work these things... Phil Haack的ASP.NET MVC 路由调试器对于弄清楚如何处理这些事情非常有用......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM