In ASP.NET MVC, we have @Url.Action
for actions. Is there something similar like @Url.Api
which would route to /api/controller?
Join them; it only takes a minute:
|
||||
|
The ApiController has a property called Url which is of type System.Web.Http.Routing.UrlHelper which allows you to construct urls for api controllers. Example:
This UrlHelper doesn't exist neither in your views nor in the standard controllers. UPDATE: And in order to do routing outside of an ApiController you could do the following:
or inside a view:
Notice the Obviously this assumes that your Api route is called
|
|||||||||||||||||||||
|
It works with the simpler form of
You might want to add an |
|||||||||||||||||||||
|
Want to be able to generate links in a typesafe manner, without hardcoded strings (controller names)? There's a nuget for that! (and it's written by Mark Seeman) https://github.com/ploeh/Hyprlinkr Works like this: Routes, as usual:
Get an URL:
Result:
|
|||
|