我可以从Sitemap生成ASP.NET MVC路由吗?

Zac*_*son 4 sitemap asp.net url asp.net-mvc routing

我正在考虑学习ASP.NET MVC即将开展的项目的框架.我可以使用高级路由根据站点地图层次结构创建长URL吗?

示例导航路径:

首页>购物>产品>家居用品>厨房>炊具>厨具>不粘锅

典型的(我认为)MVC URL:http:
//example.com/products/category/NonstickCooksets

所需网址:http:
//example.com/shop/products/household/kitchen/cookware/cooksets/nonstick

我可以这样做吗?

And*_*nea 10

扎克,如果我理解你想要无限深度的子类别.没什么大不了的,因为MVC Preview 3(我认为3或4)已经解决了.

只需定义一条路线即可

"{控制器}/{行动}/{*} categoryPath"

对于网址,例如:

http://example.com/shop/products/household/kitchen/cookware/cooksets/nonstick

你应该有一个带有Products动作的ShopController:

public class ShopController : Controller
{
...
    public ActionResult Products(string categoryPath)
    {
        // the categoryPath value would be
        // "household/kitchen/cookware/cooksets/nonstick". Process it (for ex. split it)
        // and then decide what you do..
        return View();
    }
Run Code Online (Sandbox Code Playgroud)