2

I have an MVC application with a quite complex routing (50+ routes) many with various route constraints.

e.g.:

/{optional section}/{optional section}/{optional section}/{optional section}/?p1=&p2=....

This is then picked up by a complex custom model-binder, which then converts the route-data into a complex object, with about 50 fields and complex sub-objects.

Is there any way I can programatically pass a URL into the MVC routing system, to have it spit out a model-bound object (like the standard action-method would do, when passed in via HTTP)?

Cheers.

3
  • just request the URL from the browser and debug the action method? Jun 20, 2012 at 11:47
  • 1
    Pretty sure I just asked the same question a couple of minutes ago?? stackoverflow.com/questions/11118914/…
    – Alex
    Jun 20, 2012 at 11:51
  • I'm not sure what you're trying to accomplish, but here are couple things that might be helpful. The route registration is done on app start. That means, it will be done only after you deploy and run the app the first time. If you need to current url. you can get it via the current http context HttpContext.Request.Url RouteDebugger sounds promising to debug your problem. haacked.com/archive/2011/04/13/routedebugger-2.aspx
    – HoBa
    Aug 16, 2012 at 23:54

1 Answer 1

1

The source code for one of RouteDebugger's files is here. In it you're find methods that retrieve the route list, iterate over them, and figure out which ones match a given url. You should be able to use this example to solve at least part of your problem: figuring out which route definition to use. You might also be able to figure out the classes used by the routing system, which might give you a way to do the model binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.