title: Get site url on mvc
body: <p>I want to write a little helper function that returns the site url.
  Coming from PHP and Codeigniter, I'm very upset that I can't get it to work the way I want.</p>
  
  <p>Here's what I'm trying:</p>
  
  <pre><code>@{
      var urlHelper = new UrlHelper(Html.ViewContext.RequestContext);
      var baseurl = urlHelper.Content("~");
  }
  
  &lt;script&gt;
      function base_url(url) {
  
          url = url || "";
          return '@baseurl' + url;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to return the base url of my application, so I can make ajax calls without worrying about paths. Here's how I intend to use it:</p>
  
  <pre><code>// Development
  base_url(); // http://localhost:50024
  
  // Production
  base_url("Custom/Path"); // http://site.com/Custom/Path
  </code></pre>
  
  <p>How can I do something like that?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I want absolute paths because I have abstracted js objects that makes my ajax calls.
  So suppose I have:</p>
  
  <pre><code>function MyController() {
     // ... js code
     return $resource('../MyController/:id');
  }
  
  // then
  var my_ctrl = MyController();
  my_ctrl.id = 1;
  my_ctrl.get(); // GET: ../MyController/1
  </code></pre>
  
  <p>This works when my route is <code>http://localhost:8080/MyController/Edit</code> but will fail when is <code>http://localhost:8080/MyController</code> .</p>