title: ASP .NET Core how to generate razor Urls in javascript files?
body: <p>I have a lot of javascript functions that i want to separate by logic into multiple javascript files. The problem is that all my ajax functions urls are generated by razor.</p>
  
  <pre><code> $.get('@Url.Page("Index","ViewReferenceRecordsPartial")', { productionRecordId: productionRecordId }, function (response) {
  
          $('#details').html(response)
          stopLoading(element);
      })
  </code></pre>
  
  <p>How can i keep my function like this on a js file?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is a temporary solution until there is a more maintainable solution which is pretty quick to do using data attributes.</p>
  
  <p>in a js file i have this function</p>
  
  <pre><code>function viewReferenceRecords(element, productionRecordId) {
      startLoading(element);
      $.get($(element).data('url'), { productionRecordId: productionRecordId }, function (response) {
  
          $('#details').html(response)
  
          stopLoading(element);
      })
  }
  </code></pre>
  
  <p>on my table I have a button that calls this function</p>
  
  <pre><code>&lt;button data-url="@Url.Page("Index","ViewReferenceRecordsPartial")" onclick="viewReferenceRecords(this, @Model.Id)"&gt;Details&lt;/button&gt;
  </code></pre>
  
  <p>it's very simple and easy, just store the Url generated by razor on a data attribute on the element and pass it to the function in the js file and retrieve the string generated on the data attribute.</p>