Conditional ActionLink in Razor view not rendering (asp.net mvc 3)

I scratch my head why this does not work:

@if (Model.Guid != null) { Html.ActionLink("Fil", "GetFile", new { id = Model.DocumentID }); } 

The conditional itself works like putting som random HTML in it instead of actionlink:

 @if (Model.Guid != null){<span>Test</span>} 

Similarly, the actionlink on it independently renders without problems.

Can someone tell me what is happening here?

+4
source share
1 answer

You need to put an @ sign in front of Html.ActionLink.

Like this:

 @if (Model.Guid != null) { @Html.ActionLink("Fil", "GetFile", new { id = Model.DocumentID }); } 

EDIT: Forgot to add that you do not need a half-interpretation, but you can leave it if you want.

+8
source

All Articles