Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 Mvc maproute多页面级别_Asp.net Mvc 3_C# 4.0_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 3 Mvc maproute多页面级别

Asp.net mvc 3 Mvc maproute多页面级别,asp.net-mvc-3,c#-4.0,asp.net-mvc-4,Asp.net Mvc 3,C# 4.0,Asp.net Mvc 4,无论如何,我可以减少global.ascx文件中多页面级别的重复mapRoute注册量,如下所示 routes.MapRoute("Article-level1", "{sluglevel1}/article/{id}/{article-title}", new { controller = "article", action = "detail", id = UrlParameter.Optional }); rout

无论如何,我可以减少global.ascx文件中多页面级别的重复mapRoute注册量,如下所示

    routes.MapRoute("Article-level1",
                "{sluglevel1}/article/{id}/{article-title}",
                new { controller = "article", action = "detail", id = UrlParameter.Optional });


routes.MapRoute("Article-level2",
                "{sluglevel1}/{sluglevel2}/article/{id}/{article-title}",
                new { controller = "article", action = "detail", id = UrlParameter.Optional });

routes.MapRoute("Article-level3",
                "{sluglevel1}/{sluglevel2}/{sluglevel3}/article/{id}/{article-title}",
                new { controller = "article", action = "detail", id = UrlParameter.Optional });

... more levels 4 to 10 ...
请告诉我是否有更好的方法。

您可以浏览“全面覆盖”路线参数:

但您需要将路线的结构更改为以下内容:


“article/{id}/{article title}/{*sluglevels}”
您可以执行一个简单的循环,动态生成您的路由:

int levelCount = 5;

for (int i = 1; i <= levelCount; i++)
{
    string routeName = "Article-level" + i;

    IEnumerable<string> levels = Enumerable.Range(1, i).Select(r => string.Format("{{sluglevel{0}}}", r));
    string url = string.Join("/", levels);
    url += "/article/{id}/{article-title}";

    routes.MapRoute(routeName, url,
        new { controller = "article", action = "detail", id = UrlParameter.Optional });
}

这是不可能的。我需要在文章url段前面有页面级别。您好,如果您发现一个有用的答案,请将其标记为已解决,以便其他用户可以看到您如何解决您的问题。
using System.Linq;
using System.Collections.Generic;