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.
$.get('@Url.Page("Index","ViewReferenceRecordsPartial")', { productionRecordId: productionRecordId }, function (response) {
$('#details').html(response)
stopLoading(element);
})
How can i keep my function like this on a js file?
UPDATE
Here is a temporary solution until there is a more maintainable solution which is pretty quick to do using data attributes.
in a js file i have this function
function viewReferenceRecords(element, productionRecordId) {
startLoading(element);
$.get($(element).data('url'), { productionRecordId: productionRecordId }, function (response) {
$('#details').html(response)
stopLoading(element);
})
}
on my table I have a button that calls this function
<button data-url="@Url.Page("Index","ViewReferenceRecordsPartial")" onclick="viewReferenceRecords(this, @Model.Id)">Details</button>
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.