I have an if/else statement in my details view like so:
@if (Model.SomeProperty != null)
{
Html.RenderAction("MethodName", "ContollerName", new {id=stuff});
}
else
{
<span>Is this showing?</span>
Html.ActionLink("Link Text", "MethodName", "ContollerName", new { Id = something}, null);
}
The span renders, so I know the else block was hit, but the ActionLink doesn’t appear. However, if I move it out of the else block like this, it works:
@Html.ActionLink("Link Text", "MethodName", "ContollerName", new { Id = something}, null)
I’m guessing it’s something wrong with my syntax, but I don’t see it.
Html.ActionLink()returns a string (actual anIHtmlString) containing an<a>tag.You aren’t doing anything with that string.
You need to print the string to the page by writing
@Html.ActionLink(...). (you can still do that in a code block)