i have a bunch of code where i dynamically create dropdown boxes in javascript. To prepulate the list of dropdown items, i often have code similar to below where i "inject" in the array of data items from my model so i have <%= myHTMLhelper.ShowArray(Model.List ofItems %> code inside of a javascript function.
This works perfectly except that i now have similar code that i want to reuse across files as i dont want to copy and paste code. The issue is that normally i would move my javascript code into a seperate .js file and import that into my multiple views but in this case i can't as that <% %> code wont work inside of a .js file.
Any suggestions on how can avoid copy and paste solution here ?
$(".dependencyAddButton").click(function() {
var tblID = $(this).prev("table").attr("id");
var lastRow = GetLastRow(tblID);
var existingItems = GetExistingItems('#' + tblID);
<%= myHTMLhelper.ShowArray(Model.AllApplications, "components", "componentIds") %>