I have this:
<script>var questions = ['A', 'B', 'C'];</script>
And I want something like from that to this:
<script>var questions = [@foreach (var word in Word) { word.abc; } ]</script>
That mistake because I don't know how using '' in Razor
I have this:
<script>var questions = ['A', 'B', 'C'];</script>
And I want something like from that to this:
<script>var questions = [@foreach (var word in Word) { word.abc; } ]</script>
That mistake because I don't know how using '' in Razor
Since you are using razor, you can use this.
<script>
@{ //example
var Word = new string[]{ "A", "B", "C" };
}
var questions = [@Html.Raw($"'{string.Join("','", Word)}'")];
</script>
Use <text>
block to transfer raw strings to js.
<script>
var questions = [];
@foreach (var word in Word) {
<text>
questions.push('@word.abc');
</text>
}
</script>