Question

I use the following route configuration in my MVC project:

var json = routes.MapRoute(
    name: "DefaultJson",
    url: "json/{controller}/{action}/{id}",
    defaults: new { ... }
);

json.DataTokens["force-json-result"] = new object();

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { ... }
);

This is used in a dev environment, the idea is to allow the view designers to see the entire model passed to the view without having Visual Studio.

If I use the Url resolver the first route will be used. For example, the following command

@Url.Action("Action", "Controller")

will print

/json/Controller/Action

Is there any way to ignore my first route during Url resolving?

Was it helpful?

Solution

One way is to use Url.RouteUrl. Using that you can specify a particular route name and then generate the url.

OTHER TIPS

I don't know of a way to do what you're asking but have solved the problem in a different way by adding a piece to my layout page which will output the model in json to a hidden div when the site is in development mode.

The same information is available and the developer doesn't have to switch urls to debug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top