I have an API
[RoutePrefix("things")]
public class ThingsController : APIController
{
[Route("{thingId}", Name="Things.Get")]
public Thing Get(string thingId)
{
}
}
And all is well ... except that I would like to pass the URL of this route to some JS so that it can create URLs for the request Things
So in razor mode I tried
myJavascriptObject.thingUrl = '@Url.Action("Get", "Things", new {area=""})';
but i get an empty string
I tried to give the controller an explicit name route and using
@Url.RouteUrl("Things.Get", new {areas="", thingId="foo"}") b
ut, as an empty string.
Am I really stupid? Should this work?
Update after more complicated actions.
On the MVC controller (where I need to know the route of the API controller)
var something = Url.Action("Get", "Things", new {area = ""});
var somethingWithId = Url.Action("Get", "Things", new { area = "", siteId = "fakeId" });
var somethingElse = Url.RouteUrl(new {Action = "Get", Controller = "Things", Area = ""});
var somethingElseWithId = Url.RouteUrl(new { Action = "Get", Controller = "Things", Area = "", siteId = "fakeId" });
All of them are equal to zero.
If I delete the condition area="", then I get the route, but with the name Area in it, and the route does not have the name of the region in it.
?