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
ただし、評価前に平文をレンダリングします。
助言がありますか?