在Asp.Net MVC中的路由中使用路由名称

时间:2022-12-16 03:24:57

The default Asp.Net MVC route is :

默认的Asp.Net MVC路由是:

routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
);

And, If we want to make custom routes then we can do that also, like given below :

而且,如果我们想制作自定义路线,那么我们也可以这样做,如下所示:

routes.MapRoute(
  "Privacy", // Route name
  "privacy",
   new { controller = "Home", action = "Privacy" }
);

So, my question is that what is the purpose of 'Route name' in routes given above or can we have more then one Routes with same 'Route name'.

所以,我的问题是上面给出的路线中“路线名称”的目的是什么,或者我们可以有多个具有相同“路线名称”的路线。

1 个解决方案

#1


19  

It is a shorthand way to reference to the route, by using

这是一种通过使用来参考路线的简便方法

@Html.RouteLink("Privacy");

Here an article on ASP.NET about routing, which helped me a lot...

这篇关于ASP.NET的关于路由的文章,对我帮助很大......

ASP.NET MVC Routing Overview (C#)

ASP.NET MVC路由概述(C#)

#1


19  

It is a shorthand way to reference to the route, by using

这是一种通过使用来参考路线的简便方法

@Html.RouteLink("Privacy");

Here an article on ASP.NET about routing, which helped me a lot...

这篇关于ASP.NET的关于路由的文章,对我帮助很大......

ASP.NET MVC Routing Overview (C#)

ASP.NET MVC路由概述(C#)