I'm working on an app using ASP.NET MVC. I need to be able to sometimes display a link. Other times, I just need to use text. In an attempt to accomplish this, I've written the following in my view:
@{
var showLink = !String.IsNullOrWhiteSpace(item["id"].ToString());
if (showLink) {
Html.Raw("<a href=\"#\">");
}
Html.Raw(item["name"]);
if (showLink) {
Html.Raw("</a>");
}
}
Unfortunately, this isn't working. The name does not render. However, if I put @item["name"] just above the @{ the name appears just fine. What am I doing wrong?