开发者

ASP.NET MVC Routing and Structure

I have a Customer list that will have Invoices and Emails linked to it.

I have my customer/details/1 and customer/edit/1 working as per the default route but would like to have it instead be like below

  • customer - Lists customers
  • customer/1/edit - Edit Customer ID 1
  • customer/1/details - Details of Customer ID 1
  • customer/1/invoice - Invoice List for Customer ID 1
  • customer/1/invoice/3 - Details of Invoice ID 3 for Customer I开发者_运维技巧D 1

I setup the following route (before the default route)

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

Which seems to work, but in my customer edit view I have an ActionLink like

<%=Html.ActionLink("Back to List", "Index") %>

But it gives the URL

/customer/1/index rather than just /customer or /customer/index


You can try with two routes :

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

routes.MapRoute("Customers", 
    "customer",
    new { controller = "customer", action = "List" } 
);

And as for the link :

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


Did you try

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

No need for the customer to be present in your routemap.


your route is "customer/{customerid}/{action}/{id}"

you specify action = "Index", it takes customerid from the current request (in your case, 1) and we have /customer/1/index

/customer/1 would be controller="customer", customerid = 1, action="details" according to your defaults

/customer will not match the route, cause you do not have defaults for customerid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜