MVC如何知道首先应该调用哪条路由? [英] How does MVC know which route should call first?

查看:57
本文介绍了MVC如何知道首先应该调用哪条路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void RegisterRoutes(RouteCollection routes)
       {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           routes.MapRoute(
               name: "DefaultOne",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
           );
           routes.MapRoute(
               name: "DefaultTwo",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Patient", action = "Index", id = UrlParameter.Optional }
           );
       }





我尝试过:
$ b每当我默认运行应用程序Home Controller正在调用时,$ b

。 routeconfig如何知道哪个路由应该首先调用。



What I have tried:

whenever i run the application by default Home Controller is calling. how does routeconfig know which route should call first.

推荐答案

它从一开始就经过注册的路由,一次一个,直到找到匹配。由于Home路由是列表中的第一个,因此它将首先匹配。
It goes through the registered routes from the start, one at a time, until a match is found. Since the Home route is first in the list, it'll match first.


这篇关于MVC如何知道首先应该调用哪条路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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