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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top