asp.net mvc - RouteLink to an API controller not working in MVC 4 with areas -
i use link in view point apicontroller in area. i've tried different kinds of registration. i've tried different overloads of routelink
. no success. independent how register , how try link, ~/
returned.
registrations:
var route1 = context.routes.maphttproute( "ipixdictionary_api1", "ipixdic/api/{controller}/{action}/{id}", new { id = routeparameter.optional }, new[] { "wingd.appcenter.areas.ipixdictionary.controllers" }); var route2 = context.routes.maphttproute( "ipixdictionary_api2", "ipixdic/api/{controller}/{action}/{id}", new { id = routeparameter.optional }, new[] { "wingd.appcenter.areas.ipixdictionary.controllers" }); if (route2.datatokens == null) { route2.datatokens = new routevaluedictionary(); } route2.datatokens.add("area", context.areaname);
used routelink
overloads:
@html.routelink("test11", "ipixdictionary_api1", new { httproute = true, controller = "enginesapi" }) @html.routelink("test12", "ipixdictionary_api1", new { httproute = true, controller = "enginesapi" }, null) @html.routelink("test13", "ipixdictionary_api1", new { httproute = true, controller = "enginesapi", area = "ipixdictionary" }) @html.routelink("test14", "ipixdictionary_api1", new { httproute = true, controller = "enginesapi", area = "ipixdictionary" }, null) <br /> @html.routelink("test21", "ipixdictionary_api2", new { httproute = true, controller = "enginesapi" }) @html.routelink("test22", "ipixdictionary_api2", new { httproute = true, controller = "enginesapi" }, null) @html.routelink("test23", "ipixdictionary_api2", new { httproute = true, controller = "enginesapi", area = "ipixdictionary" }) @html.routelink("test24", "ipixdictionary_api2", new { httproute = true, controller = "enginesapi", area = "ipixdictionary" }, null) <br />
everything works fine without areas, won't work areas.
any ideas?
found solution. api controller not need action in registration :-)
so following solution:
context.route.maphttproute( "ipixdictionary_api", "ipixdic/api/{controller}/{id}", new { id = routeparameter.optional }); @html.routelink("json", "ipixdictionary_api", new { httproute = true, controller = "enginesapi" })
Comments
Post a Comment