Asp.net mvc ASP.NET MVC路由和结构

Asp.net mvc ASP.NET MVC路由和结构,asp.net-mvc,routes,Asp.net Mvc,Routes,我有一个客户名单,将发票和电子邮件链接到它 我让我的customer/details/1和customer/edit/1按照默认路线工作,但希望改为如下所示 客户-列出客户 客户/1/编辑-编辑客户ID 1 客户/1/详细信息-客户ID 1的详细信息 客户/1/发票-客户ID 1的发票列表 客户/1/发票/3-客户ID 1的发票ID 3的详细信息 我在默认路由之前设置了以下路由 routes.MapRoute("CustomerActions", "customer/{customer

我有一个客户名单,将发票和电子邮件链接到它

我让我的customer/details/1和customer/edit/1按照默认路线工作,但希望改为如下所示

客户-列出客户 客户/1/编辑-编辑客户ID 1 客户/1/详细信息-客户ID 1的详细信息 客户/1/发票-客户ID 1的发票列表 客户/1/发票/3-客户ID 1的发票ID 3的详细信息 我在默认路由之前设置了以下路由

routes.MapRoute("CustomerActions", 
    "customer/{customerid}/{action}/{id}",
    new { controller = "customer", action = "details", id="" } 
);
这似乎可行,但在我的客户编辑视图中,我有一个ActionLink,如

<%=Html.ActionLink("Back to List", "Index") %>
但它给出了URL

/客户/1/索引而不仅仅是/customer或/customer/index

您尝试过吗

"{controller}/{action}/{id}",
            //    new { controller = "Customer", action = "Details", id = ""}

不需要客户出现在您的路线图中。

您的路线是客户/{customerid}/{action}/{id}

您指定action=Index,它从您的案例中的当前请求中获取customerid,1 我们有/customer/1/index

/根据您的默认设置,customer/1将是controller=customer、customerid=1、action=details


/客户将与路线不匹配,因为您没有customerid的默认值。您可以尝试使用两条路线:

routes.MapRoute("Customer", 
    "customer/{customerid}/{action}/{id}",
    new { controller = "customer", action = "details", id="" } 
);

routes.MapRoute("Customers", 
    "customer",
    new { controller = "customer", action = "List" } 
);
至于链接:

<%=Html.RouteLink("Back to List", "Customers", null) %>

但是如果我指定customer/1/details,它会将1视为操作,将details视为id