I just started working on an application with two areas (base system master / details type system). I am exploring the benefits of nice routing features in MVC (4 specifically), and I'm "just not" I suppose. "
Currently, the only defined route is the base one:
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional } );
this is normal, it works with the areas that we have identified, so I assume that it should know where the user is, and direct it to the appropriate controller based on contexts on the location / area in which the user is located. good..
Now I'm trying to configure a new route that can handle
/someController/someAction/{statusName}
and in particular something like:
/OrderManager/List/New
AND
/OrderManager/List/Viewed
where "New" is the status of "New" and has the signature "Action":
public ActionResult List(string statusName)
I assumed that I could just add a new route below the default identifying “statusName” instead of Id, but, of course, how mechanism H will know the difference between:
/ controller1 / action
/ controller2 / action2 / new
I tried to add a “static” route as
routes.MapRoute("Default", "ControllerName/ControllerAction/{statusName}", new { statusName = UrlParameter.Optional } );
I thought that I can "hiJack" only one route and do something special with it, but in order to know what to use, the router stops at the first match ?? I guess this was the wrong way to solve this problem anyway.
so now I get to the idea of getting to something like:
/somecustomroutename/somesortValue
ex. / OrderManagerList / viewNew
where these routes will be mostly aliases. I thought adding the following route would do the trick:
routes.MapRoute("Default_List", "OrderManagerList/{statusName}", new {controller="OrderManager", action="List", statusName= UrlParameter.Optional } );
with the appropriate action on the OrderManager controller:
public ActionResult List(string statusName)
no matter what I try, the argument is null, or "the resource cannot be found"
I know that controllers must have a corresponding View file. But this is not a problem, the problem is in my attempt to understand routing.
SB my questions .. basically, what am I missing about routing in MVC (4)? even some good articles for a simpleton, how am I to understand?
my understanding; identify the route and display its “endpoint” .. however, I think I don’t understand the assumption that the machine is doing ..
In any case, let me know if further explanation / editing is required.
early.