I want to get data from a C# function, store it in a hidden HTML field, and then access it in jQuery.
This is what I'm thinking:
C#:
public static string getDuckbillDepts()
{
List<string> duckbillDptsStr = new List<string>();
for (int i = 2; i < 100; i++)
{
duckbillDptsStr.Add(i);
}
return string.Join(",", duckbillDptsStr); // <-- will this work?
}
Razor:
// I first wanted to use List<int> but then realized HTML would probably mutiny if I tried to give it that data type
@{string duckbillDeptsCSV = CCRReporterUtils.getDuckbillDepts()}
HTML:
<input type="hidden" name="AllDepts" id="hiddenAllDepts" value="@duckbillDeptsCSV" />
jQuery:
var deptsArray = $('hiddenAllDepts').val();
...but "duckbillDeptsCSV" in the HTML is red, indicating (right?) that it's confusing the compiler. Am I doing it wrong?