嵌套资源ASP.Net MVC支持? [英] ASP.Net MVC support for Nested Resources?

查看:101
本文介绍了嵌套资源ASP.Net MVC支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找类似可通过Rails的嵌套的REST风格的路线功能的路由选择。上MvcContrib的SimplyRestful项目不会出现有活性的任何再也不似乎是与1.0 MVC释放电流

这是我要找的,

URI方案

/活动/ 10 /任务/ 1 /编辑
要么
/活动/ 10 /任务/编辑/ 1

我根本就没有能够得到它的工作和所有我整个运行文档描述了非嵌套场景。它似乎并不像它会是那么难......

这是我一直在使用...


    routes.MapRoute(NULL,
        活动/ {} activityId /任务/ {}动作/(编号),
        新{控制器=任务,行动=编辑,activityId =,ID =});


解决方案

添加默认值活动

  routes.MapRoute(NULL,
    活动/ {} activityId /任务/ {行动} / {ID} / {}活动,
    新{
        控制器=任务,
        行动=编辑,
        ID =,
        activityId =,
        活性=});

也请记住,这条路只会拿起网址,表格上

  /活动/ 10 /编辑/ 1 / theActivity

而你的榜样

  /活动/ 10 /编辑/ 1

将被默认路由回升,设定路线值

 控制器=活动
行动=10
ID =编辑/ 1

菲尔哈克的路由调试了解ASP.NET MVC是非常有用的搞清楚如何工作的这些事情...

I'm looking for a routing option similar to the nested RESTFul routes functionality available through Rails. 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.

This is the uri scheme I'm looking for,

/Activity/10/Task/1/Edit or /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:

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...

这篇关于嵌套资源ASP.Net MVC支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆