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中运行无根的联系人。
*删除*联系人的路线。它要求'ContactController'只能通过'root/Contact'访问。默认的根目录足以匹配控制器名称和控制器。 –