使用ASP.NET MVC从数据库路由层次结构路径 [英] Routing an hierarchical path from DB with ASP.NET MVC

查看:79
本文介绍了使用ASP.NET MVC从数据库路由层次结构路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以按如下所示路由层次结构路径以映射数据库中的关系:

Is it possible to route an hierarchical path to map a relation from the database as follows:

比方说,我有一个元组/实体页面",它与页面"(本身)具有mtm关系,并且我希望能够合并每个页面的slug值来找到合适的页面,如下所示:

Let's say I have an tuple/entity "page" with an m-t-m relation to a "page" (itself) and I want to be able to combine the slug-value of each page to find an appropriate page, like so:

mydomain.com/firstpage/secondpage/thirdpage

其中firstpagesecondpagethirdpage的类型为页面",第三页引用第二页,依此类推.

where firstpage, secondpage and thirdpage are of type "page" and the third page references to the second page etc.

您将如何使用ASP.NET MVC路由实现此目标?

How would you implement this with ASP.NET MVC routing?

推荐答案

好,以为我解决了!

我发现路由时可以使用*(全部捕获参数).

I found out that there is a * (catch-all parameter) that can be used when routing.

例如:

routes.MapRoute(
    "Pages",
    "{*pageQuery}",
    new { controller = "Page", action = "GetPage" }
);

然后在我的控制器中,我可以使用正则表达式或简单的拆分来解决该段的每个部分. :)

Then in my controller I can use regular expressions or a simple split to resolve each part of the slug. :)

这篇关于使用ASP.NET MVC从数据库路由层次结构路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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