Reputation: 29229
I have the following Mvc 4 razor code
@foreach (var item in Model.DealDetails) {
<tr>
<td>@Html.DisplayFor(m => item.DetailId)</td>
<td>@Html.DisplayFor(m => item.AppGuid)</td>
....
</tr>
I want to generate a link in another <td>
column for each row. The link will look like
<a href="/Control/Action/{item.DetailId}?h={item.AppGuid}">
Link text
</a>
The control and action are in the same project. Is there any help function to do it? I want the link not to be created when item.AppGuid is null.
Upvotes: 0
Views: 41
Reputation: 15866
@foreach (var item in Model.DealDetails) {
<tr>
<td>@Html.DisplayFor(m => item.DetailId)</td>
<td>@Html.DisplayFor(m => item.AppGuid)</td>
@if(item.AppGuid != null){
<td>@Html.ActionLink("text", "action", "controller", new { id = item.DetailId , h = item.AppGuid}, null)</td>
}
</tr>
Upvotes: 1