简体   繁体   English

如果Baz值在Razor View中为true,则使用Asterick显示字段

[英]Show Field with Asterick if Bool value is true in Razor View

I am creating a table in my Razor view that if a bool value is true then show an asterick next to one of the fields. 我正在Razor视图中创建一个表,如果bool值为true,则在其中一个字段旁边显示一个星号。 The code I have looks correct but it is coming out blank on all rows. 我的代码看起来正确,但是在所有行上都是空白。 It should be the number in that field if false and the number in that field* if true. 如果为false,则应为该字段中的数字;如果为true,则应为该字段中的数字*。

Here is the code: 这是代码:

@{ 
     string ToDisplay = item.MinimumOnHandQuantity.ToString();
     if (item.UseForecast)
     {
           ToDisplay += "*";
     }
}
@Html.Display(ToDisplay) 

Try this 尝试这个

@{ 
     string ToDisplay = item.MinimumOnHandQuantity.ToString();
     if (item.UseForecast)
     {
           ToDisplay += "*";
     }
}
@Html.Raw(ToDisplay) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM