I'm having trouble displaying (rather than displaying) plain text in an else block.
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 blocks work fine. Text is only displayed when true. However, the text of the else block displays when the page loads, and not only if it only evaluates to false.
I tried using
Hmtl.Raw("No Careerfields associated with ") <text>No Careerfields associated with @ViewBag.SelectedDivisionTitle</text> @:No Careerfields associated with @ViewBag.SelectedDivisionTitle
But before evaluating it still provides clear text.
Any suggestions?
asp.net-mvc-3 razor
Erik
source share