0

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

1
  • Pls take a look. Similar question and answer Commented May 16, 2020 at 23:01

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

Use <text> block to transfer raw strings to js.

<script>
var questions = [];
@foreach (var word in Word) { 
    <text>
  questions.push('@word.abc');
    </text>
} 
</script>

Comments