title: Generate URL of a versioned API action with IUrlHelper
body: <p>In my ASP.NET Core project I'm using <a href="https://github.com/Microsoft/aspnet-api-versioning" rel="nofollow noreferrer">aspnet-api-versioning</a> like so:</p>
  
  <pre><code>[ApiVersion("1.0")]
  [Route("api/v{version:apiVersion}/users")]
  [Authorize]
  public class UserController : Controller
  {
  
    [HttpGet, MapToApiVersion("1.0")]
    public async Task&lt;IActionResult&gt; GetUsers([FromQuery] string searchString, [FromQuery] bool allOrganizations = false)
    {
     ...
    }
  
  }    
  </code></pre>
  
  <p>So the request is sent to: <code>GET /api/v1/users</code>.</p>
  
  <p>When adding another version of this action I would just add the attribute <code>MapToApiVersion("2.0")</code> so it would be <code>GET /api/v2/users</code>.
  That's all fine.</p>
  
  <p>However in a view I call this action with ajax like so:</p>
  
  <pre><code>$.ajax({
  url: '@Url.Action("GetUsers", "User", new{version = 1})' + "?searchString=" + $("#user-search").val() + "&amp;allOrganizations=true",
  type: "GET",
  success: function(data) {
  response($.map(data,
  function(obj) {
  return {
          //some mapping
         };
   }));
  }
  });
  </code></pre>
  
  <p>This calls the endpoint:<code>/User/GetUsers?version=1?searchString={searchString}&amp;allOrganizations=true</code></p>
  
  <p>So it appends the version as a query parameter instead of route parameter.</p>
  
  <p>If I don't add the  <code>new {version = 1}</code> it's the same just without the 'version' query parameter.</p>
  
  <p>I've also tried using <code>@Url.RouteUrl("Get_Users", new {version =1})</code> and naming the action with <code>[HttpGet("Get_Users"), MapToApiVersion("1.0")]</code> but that just appends the query parameters to the current url.</p>
  
  <p>However if I change the <strong>Controllers</strong> route attribute from <code>[Route("api/v{version:apiVersion}/users")]</code> to <code>[Route("api/users")]</code> and ommit the version parameter, the ajax call works fine.</p>
  
  <p>So is there any way to use <code>IUrlHelper</code> (or some other way) to get the correct route to a versioned action besides hardcoding the url string? Or am I doing versioning wrong in some way?</p>
  
  <p>I may just be complicating here, but I still think this should work, no?</p>