2016-02-29 103 views
0

我在“根”文件夹中有2个名为“索引”和“联系人”的视图。我在global.asax中完成了以下路由。 ,ROOR/Contact.cshtml在MVC中删除控制器名称

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

      routes.MapRoute(
       name: "Contact", 
       url: "root/Contact", 
       defaults: new { controller = "Root", action = "Contact", id = UrlParameter.Optional } 
      ); 
      routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Root", action = "Index", id = UrlParameter.Optional } 
      ); 

     } 

当我运行的网址是http://localhost:8889/加载索引页。 但当我运行http://localhost:8889/Contact得到404错误。当我运行localhost时:8889/Root/Contact正在成功加载。 我想在URL中运行无根的联系人。

+0

*删除*联系人的路线。它要求'ContactController'只能通过'root/Contact'访问。默认的根目录足以匹配控制器名称和控制器。 –

回答

0

尝试从您的Contact路线中删除root/,如下所示。

routes.MapRoute(
    name: "Contact", 
    url: "Contact", 
    defaults: new { controller = "Root", action = "Contact", id = UrlParameter.Optional } 
    ); 
+0

为什么不完全删除路由? –

相关问题