本文介绍了删除或替换现有的RouteTable路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个ASP.NET MVC 2.0 preVIEW 1的应用程序,并开始创建一个包含自己的路线部分地区。

我希望有一种方式覆盖在主项目这些路由。我当然不使用相同的名称添加一个新的途径。我可以看到RouteTable.Routes.Remove(RouteBase项目),但不知道如何使用它。

  //需要重新添加之前删除PostIndex
routes.MapAreaRoute(
                OurAreaNameSpace
                PostIndex
                后/指数/ {}当前页,
                新{控制器=邮报,行动=索引,当前页=},
                新的String [] {OurAreaNameSpace.Controllers}
            );


解决方案

如何在这?

  RouteTable.Routes.Remove(RouteTable.Routes [PostIndex]);

I got a ASP.NET MVC 2.0 Preview 1 app and started to create some areas which contains their own routes.

I want to have a way to overwrite these routes in the main project. I can of course not add a new route with the same name. I can see the RouteTable.Routes.Remove(RouteBase item) but not sure how to use it.

//Need to remove "PostIndex" before adding it again
routes.MapAreaRoute(
                "OurAreaNameSpace",
                "PostIndex",
                "post/index/{currentPage}",
                new { controller = "Post", action = "Index", currentPage = "" },
                new string[] { "OurAreaNameSpace.Controllers" }
            );
解决方案

How do in this?

RouteTable.Routes.Remove(RouteTable.Routes["PostIndex"]);

这篇关于删除或替换现有的RouteTable路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 21:06