How can I get the url from web api in my view?
Example (from the msdn-blog):
[RoutePrefix(\"reviews\")]
public class ReviewsController : ApiControlle
In WebApi2 when using AttributeRouting, route names are named by default Controller.Action, but you could specify a RouteName also:
[RoutePrefix("reviews")]
public class ReviewsController : Controller
{
// The route name is defaulted to "Reviews.Index"
[Route]
public ActionResult Index() { ... }
// The route name is "ShowReviewById"
[Route("{reviewId}"), RouteName("ShowReviewById")]
public ActionResult Show(int reviewId) { ... }
// The route name is by default "Reviews.Edit"
[Route("{reviewId}/edit")]
public ActionResult Edit(int reviewId) { ... }
Then to call it in the view you only need to set the route name and send the parameters as an anonymous object:
// Outputs: /reviews/123
@Url.Action("ShowReviewById", new { reviewId = 123 })
// Outputs: /reviews/123/edit
@Url.Action("Reviews.Edit", new { reviewId = 123 })