Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:06:37+00:00 2026-05-30T21:06:37+00:00

In ASP.NET MVC, we have @Url.Action for actions. Is there something similar like @Url.Api

  • 0

In ASP.NET MVC, we have @Url.Action for actions. Is there something similar like @Url.Api which would route to /api/controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:06:38+00:00Added an answer on May 30, 2026 at 9:06 pm

    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:

    public class ValuesController : ApiController
    {
        // GET /api/values
        public IEnumerable<string> Get()
        {
            // returns /api/values/123
            string url = Url.Route("DefaultApi", new { controller = "values", id = "123" });
            return new string[] { "value1", "value2" };
        }
    
        // GET /api/values/5
        public string Get(int id)
        {
            return "value";
        }
    
        ...
    }
    

    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:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            string url = Url.RouteUrl(
                "DefaultApi", 
                new { httproute = "", controller = "values", id = "123" }
            );
            return View();
        }
    }
    

    or inside a view:

    <script type="text/javascript">
        var url = '@Url.RouteUrl("DefaultApi", new { httproute = "", controller = "values", id = "123" })';
        $.ajax({
           url: url,
           type: 'GET',
           success: function(result) {
               // ...
           }
        });
    </script>
    

    Notice the httproute = "" route token which is important.

    Obviously this assumes that your Api route is called DefaultApi in your RegisterRoutes method in Global.asax:

    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have a problem by Url.Action in asp.net MVC. this is a sample: Url.Action(index,
I have only a route in my ASP.NET MVC App: routes.MapRoute( Post, post/{url}, new
ASP.Net MVC Controllers have several methods of forwarding control to another controller or action.
I'm using ASP.NET MVC and have a model which has an image (byte array)
I really like the MVC way and have actually enjoyed learning ASP.NET MVC (I
I am using ASP.NET MVC with jQuery. I have the following MVC Action that
I'm using ASP.NET MVC and would like to get Model information for use within
I have a simple ASP.Net MVC View which contains an FCKeditor text box (created
This is how I generate a URL in ASP.NET MVC currently: Url.Action(Index, new {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.