Reputation: 3779
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.
Upvotes: 0
Views: 108
Reputation: 24125
It should be:
@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 Html.RenderAction
works directly with stream so it doesn't need it, but Html.ActionLink
returns MvcHtmlString
which needs to be outputed "in place".
Upvotes: 1
Reputation: 888177
Html.ActionLink()
returns a string (actual an IHtmlString
) 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)
Upvotes: 2