If语句和Html.Razor MVC 3中的ActionLink


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

我有这个,如果hasttypes为真,它将创建一个动作链接。但是上面的代码不起作用。在这些列中显示为空。

我想你忘记了一个用于输出的@:

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

您需要实际呈现输出链接。您当前的代码生成了一个链接,但实际上并没有对它做任何事情。注意下面额外的@:

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

最新更新