title: Generate URL in HTML helper
body: <p>Normally in an ASP.NET view one could use the following function to obtain a URL (not an <code>&lt;a&gt;</code>):</p>
  
  <pre><code>Url.Action("Action", "Controller");
  </code></pre>
  
  <p>However, I cannot find how to do it from a custom HTML helper. I have </p>
  
  <pre><code>public class MyCustomHelper
  {
     public static string ExtensionMethod(this HtmlHelper helper)
     {
     }
  }
  </code></pre>
  
  <p>The helper variable has the Action and GenerateLink methods, but they generate <code>&lt;a&gt;</code>’s. I did some digging in the ASP.NET MVC source code, but I could not find a straightforward way.</p>
  
  <p>The problem is that the Url above is a member of the view class and for its instantiation it needs some contexts and route maps (which I don’t want to be dealing with and I’m not supposed to anyway). Alternatively, the instance of the HtmlHelper class has also some context which I assume is either supper of subset of the context information of the Url instance (but again I don’t want to dealing with it).</p>
  
  <p>In summary, I think it is possible but since all ways I could see, involve some manipulation with some more or less internal ASP.NET stuff, I wonder whether there is a better way.</p>
  
  <p><strong>Edit:</strong> For instance, one possibility I see would be:</p>
  
  <pre><code>public class MyCustomHelper
  {
      public static string ExtensionMethod(this HtmlHelper helper)
      {
          UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
          urlHelper.Action("Action", "Controller");
      }
  }
  </code></pre>
  
  <p>But it does not seem right. I don't want to be dealing with instances of UrlHelper myself. There must be an easier way.</p>