mercredi 8 juillet 2015

How is URL Routing handled when the URLs are 3+ levels deep? (RESTful URLs)

So let's say you need to have these URLs in your RESTful routing:




I assume that all of these actions would need to be in the same controller (i.e. Company) and I also assume that the routing would look something like this in Global.asax:

public static void RegisterRoutes(RouteCollection routes)
     routes.MapRoute("mission", "Company/Product/{action}/{id}",
          new { controller = "Company", id = "" });

     routes.MapRoute("mission", "Company/Contract/{action}/{id}",
          new { controller = "Company", id = "" });

          new { controller = "Home", action = "Index", id = "" } 

The problem arises when trying to cram all of this into the one controller (and, again, my assumption is that having all of this in the same controller is correct) because the controller action names will mess everything up. Here is what I mean by this:

In this example, we will need controller actions named the following in the Company controller:

About (for Company/About)

ProductView (for /Company/Product/View)
ProductEdit (for /Company/Product/Edit)

ContactView (for /Company/Contact/View)
ContactEdit (for /Company/Contact/Edit)

These action names will cause collisions, however, in the routing. For example:

@Html.ActionLink("View this Product", "View", "Company");
@Html.ActionLink("View this Contract", "View", "Company");

Both of these ActionLinks point to the same action in the controller (i.e. the View action).

If we manually craft the links (instead of using ActionLink), the same thing happens.

How would you solve this issue? My goal is to be as RESTful as possible.

Aucun commentaire:

Enregistrer un commentaire