DevSharp
DevSharp

Reputation: 291

If statement and Html.ActionLink in Razor MVC 3

@if (item.hasTypes.Value == true) { 
    Html.ActionLink(item.marketGroupName, "Index", new { id = item.marketGroupID });
}

I have this so that if the hasTypes is true, it will create an actionlink. But the above code does not work. It is showing empty in those columns.

Upvotes: 10

Views: 10159

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

I think you forgot an @ which is used to output:

@if (item.hasTypes.Value) { 
    @Html.ActionLink(item.marketGroupName, "Index", new { id = item.marketGroupID });
}

Upvotes: 21

marcind
marcind

Reputation: 53183

You need to actually render the link to the output. Your current code produces a link but doesn't actually do anything with it. Notice the extra @ below:

@if (item.hasTypes.Value == true) { 
    @Html.ActionLink(item.marketGroupName, "Index", new { id = item.marketGroupID });
}

Upvotes: 3

Related Questions