两条简单的路线无法正常工作

时间:2014-05-06 03:29:53

标签: c# asp.net-mvc asp.net-mvc-routing

如何使这条路线有效:

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

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

如果我需要,我需要打电话:

/ModalityName/SomeController/SomeAction/SomeId

/SomeController/SomeAction/SomeId

但是mvc默认的第二条路线无效。

我只需要一些时间来通知模态,这样我就可以根据

获得一些内容

1 个答案:

答案 0 :(得分:0)

按顺序评估路由是否与传入的URL匹配

routes.IgnoreRoute(" {资源}个.axd / {*} PATHINFO&#34);

routes.MapRoute(
    name: "Custom",
    url: "ModalityName/{controller}/{action}/{id}",
    defaults: new
    {
        controller = "ModalityName",
        action = "action",
    }
);



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

}

更多信息阅读链接:http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC