剃刀语法 - foreach 循环 [英] razor syntax - foreach loop

查看:45
本文介绍了剃刀语法 - foreach 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想吐槽:s 等于 1s 等于 2s 等于 3

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

但是我收到了各种各样的错误,因为 Visual Studio 认为 {} 之间是代码,但我希望它是标记.

But I'm getting all sorts of errors because Visual Studio thinks that what is between the {}'s is code, but I want it to be markup.

推荐答案

刚看到这个 今天早上在 ScottGu 的博客上:在该行之前使用 @::

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<br/>
}

或者,使用 标签:

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

这篇关于剃刀语法 - foreach 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆