在Razor中,布尔值可以通过以下方式打印为'value':
@{
bool myBoolValue = true;
string boolString = myBoolValue ? "value" : "other value";
}
@boolString
在上面的示例中,我们首先定义了一个布尔变量myBoolValue
,然后使用条件运算符(?:)将其转换为字符串boolString
。如果myBoolValue
为true
,则boolString
将被赋值为"value",否则将被赋值为"other value"。
最后,在HTML中使用@boolString
将布尔值打印出来。如果myBoolValue
为true
,则打印出"value"。
下一篇:布尔值在数组选择中