剃刀视图中的三元运算符 returns 代码为字符串
ternary operator in razor view returns code as string
我想格式化数据,但我得到了错误的结果,我该如何解决?
<div>
@string.IsNullOrEmpty(Model.Customer.State) ? @Model.Customer.Country : @string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State);
</div>
它returns:
True ? French: French, ;
您只需要添加一些括号,以便将其视为一个单独的语句块...
<div>
@(string.IsNullOrEmpty(Model.Customer.State) ? Model.Customer.Country : string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State));
</div>
您必须用方括号括起整个条件:
<div>
@(string.IsNullOrEmpty(Model.Customer.State) ? Model.Customer.Country : string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State))
</div>
我想格式化数据,但我得到了错误的结果,我该如何解决?
<div>
@string.IsNullOrEmpty(Model.Customer.State) ? @Model.Customer.Country : @string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State);
</div>
它returns:
True ? French: French, ;
您只需要添加一些括号,以便将其视为一个单独的语句块...
<div>
@(string.IsNullOrEmpty(Model.Customer.State) ? Model.Customer.Country : string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State));
</div>
您必须用方括号括起整个条件:
<div>
@(string.IsNullOrEmpty(Model.Customer.State) ? Model.Customer.Country : string.Format("{0}, {1}", Model.Customer.Country, Model.Customer.State))
</div>