我在 else 块中显示(而不是显示)纯文本时遇到问题。
if (Model.CareerFields != null && ViewBag.CFCount > 0)
{
<h3>Careerfields Listing</h3>
<table>
<tr>
<th></th>
<th>Careerfield Name</th>
</tr>
@foreach (var item in Model.CareerFields)
{
<tr>
<td>
@Html.ActionLink("Select", "Index", new { careerFieldID = item.CareerFieldId })
</td>
<td>
@item.CareerFieldName
</td>
</tr>
}
</table>
}
else
{
No Careerfields associated with @ViewBag.SelectedDivisionTitle
}
if 块工作正常。文本仅在 true 时呈现。但是,else 块文本会在页面加载时呈现,而不是仅在其评估为 false 时呈现。
我试过使用
Hmtl.Raw("No Careerfields associated with ")
<text>No Careerfields associated with @ViewBag.SelectedDivisionTitle</text>
@:No Careerfields associated with @ViewBag.SelectedDivisionTitle
但它仍然在评估之前呈现明文。
有什么建议么?