title: How can I remove the controller and action from the url and only get the url in MVC
body: <p><strong>EDIT</strong>
  I may not have worded my problem very well. The actual problem is not in the routing as much as it is in trying to derive the actual url of the request.</p>
  
  <p>The application can be deployed on many seperate machines. For example</p>
  
  <blockquote>
    <p><a href="http://localhost:2990/Client/List" rel="nofollow noreferrer">http://localhost:2990/Client/List</a></p>
    
    <p><a href="http://avapd024/llne.dev/Client/List" rel="nofollow noreferrer">http://avapd024/llne.dev/Client/List</a></p>
    
    <p><a href="http://machine123:81/llne.prod/Client/List" rel="nofollow noreferrer">http://machine123:81/llne.prod/Client/List</a></p>
  </blockquote>
  
  <p>etc etc</p>
  
  <p>The reason I can't use Action.Link or html helpers is that I need to build the link before I return it to the view as it populates as  grid taking JSON (datatables.net) and NOT and the time the view is being rendered</p>
  
  <p>thanks</p>
  
  <p>I need to populate a grid with a list of items as links pointing to a different controller and action and id.</p>
  
  <p>for example; 
  when I load the grid the url is as follows: <code>http://localhost:2990/Client</code> which is fine. The grid contains a link like the following</p>
  
  <pre><code>JSID = "&lt;a href='http://" + RequestUrl + "/trainingdelivery/Get/" + referral.ReferralId + "'&gt;Training Delivery&lt;/a&gt;",
  </code></pre>
  
  <p>the controller is 'trainingdelivery' and action is 'Get' and id = referralid which results in a url like <code>http://localhost:2990/trainingdelivery/Get/12345</code>). This is fine on my local machine but when we deploy it goes to a server with a different url like <code>http://avapd024/llne.dev:81/</code> as you can see the 'llne.dev:81' is the IIS web and I need to get the url to wherever it is to recognise its location and go to the correct controller and action.</p>
  
  <p>I tried using the request object and I could probably hack around in there to get it but I would like to know if there are any better solutions?</p>
  
  <p>thanks</p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
              routes.IgnoreRoute("{resource}.js/{*pathInfo}");
  
              routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
  
              routes.MapRoute(
                  "Default", // Route name
                  "{controller}/{action}/{id}", // URL with parameters
                  new { controller = "Home", action = "Index", id = "" } // Parameter defaults
                  );
          }
  </code></pre>
  
  <p>AJAX CALL IN JQUERY</p>
  
  <pre><code>oTable = $('#referralTable').dataTable(
          {
  
              "bFilter": true,
              "bJQueryUI": true,
              "sPaginationType": "full_numbers",
              "bAutoWidth": false,
              "sAjaxSource": "../Client/Fetch",
              "aoColumns": [
              //client details
                              {"bVisible": false, "sName": "ReferralId" },
                              { "sTitle": "CRN", "sName": "CRN" },
                              { "sTitle": "JSID", "sName": "JSID" },
                              { "sTitle": "Name", "sName": "Name" }
  ]
  });
  </code></pre>
  
  <p>the sAjaxSource is the call that loads the grid with data and returns JSON. By the time it is returned it needs to be formatted correctly.</p>