razor syntax - foreach loop

前端 未结 3 1266
死守一世寂寞
死守一世寂寞 2021-02-06 20:19
@foreach (string s in \"1,2,3\".Split(\',\')) {
  s is equal to @s
}

I want to spit out: s is equal to 1 s is equal to 2 s is equal to 3

3条回答
  •  忘了有多久
    2021-02-06 20:56

    Just saw this on ScottGu's blog this morning: use @: before that line:

    @foreach (string s in "1,2,3".Split(',')) {
      @: s is equal to @s
    }

    Alternately, use the tag:

    @foreach (string s in "1,2,3".Split(',')) {
      s is equal to @s
    }

提交回复
热议问题