![.net mvc Razor 三元运算判断赋值 ?: .net mvc Razor 三元运算判断赋值 ?:](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
预期效果:
当Model中的Age数字列值为0时,不显示该值。
<input type="text" class="form-control onlyPositiveNumber" id="Age"
maxlength="3" style="text-align:right;width:80px; " value='@(Model.Age == 0? "":Model.Age.ToString())' >
预期效果:
根据ViewData中的值,判断radio是否需要被选中
<input type="radio" id="rdoReportTypeBS" name="ReportType" disabled="disabled" value="BS"
@(ViewData["ReportType"].ToString().ToUpper() == "BS"?"checked":"") >