Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am scratching my head as to why not this isn't working:

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

The conditional on its own is working as putting som random HTML in there instead of an actionlink works:

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

Likewise the actionlink on it's own renders without a problem.

Could anybody clue me in to what is going on here?

like image 221
user109657 Avatar asked Jun 03 '11 10:06

user109657


1 Answers

You need to put an @ sign before the Html.ActionLink.

Like this:

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

EDIT: Forgot to add that you don't need the semi colon, but you can leave it in if you want.

like image 109
Tom Chantler Avatar answered Nov 15 '22 04:11

Tom Chantler