ASP.NET MVC页/子页面的路由 [英] ASP.NET MVC page/subpage routing

查看:94
本文介绍了ASP.NET MVC页/子页面的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何处理以下情形。一般情况下,我有一个表中的一堆纪录。所有这些具有ID和PARENTID字段以形成树。

I'm try to figure out how to handle the following scenario. In general, i have a bunch of records in a table. All of these have ID and ParentID fields to form a tree.

Page1
 - Page2
 - Page3
Page4
 - Page5
 -- Page6

现在,我想我的第3页和第6页的路线要像 /第1页/第6页 /第3页/第5页/第6页 respectivelly。也就是说,我要在URL中包括所有的父母。

Now, i want my routes for Page3 and Page6 to be like /Page1/Page6 and /Page3/Page5/Page6 respectivelly. That is, i want to include all parents in the URL.

如何设置我的控制器动作/路由实现上述结果?

How to set my controller action/routing to achieve the above result?

编辑:忘了提的是,上述结构将是动态的 - 可以添加节点/删除/改变家长等

Forgot to mention that the above structure will be dynamic - nodes can be added/deleted/change parent, etc.

推荐答案

您可以使用通配符,请参阅:的 http://www.vergentsoftware.com/blogs/ckinsman/ASPNETMVCWildcardRoutes.aspx

You could use a wildcard match, see: http://www.vergentsoftware.com/blogs/ckinsman/ASPNETMVCWildcardRoutes.aspx

一个可能的路径:

routes.MapRoute("SomeName", "{*Page}", new { controller = "ControllerName", action = "ActionName" });

和在行动接受字符串页,手动解析它,也许有分流?

and in the action accept the string Page, and parse it manually, perhaps with a split?

编辑:这也可能是有用的:<一href=\"http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx\" rel=\"nofollow\">http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

edit: this might also be useful: http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

这篇关于ASP.NET MVC页/子页面的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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