Span inside @Html.Actionlink

Asked

Viewed 376 times

3

I have the following column of a table:

<td style="font-size:10%">
   <p class="list-group-item-text">
      @Html.ActionLink((string)item.cidadenome, "Cidade", "Cidade", new { cidadecod = item.cidadecod, contratocod = item.contratocod }, new { @class = "list-group-item active", @style = "font-size: 18px" } )
      <span class="badge" style="font-size: 12px; background-color:@item.statusservidor_stts">
          @item.statusservidor
      </span>
    </p>
</td>

But the content of Span is displayed below Actionlink, as illustrated in the image below: inserir a descrição da imagem aqui

I would like Span to be displayed in Action Link (in the blue part) after the number. What should I do ?

2 answers

3


Use @Url.Action instead of @Html.ActionLink:

<td style="font-size:10%">
   <p class="list-group-item-text">
      <a href="@Url.Action("Cidade", "Cidade", new { cidadecod = item.cidadecod, contratocod = item.contratocod })" class = "list-group-item active", style = "font-size: 18px">
          @item.cidadenome
          <span class="badge" style="font-size: 12px; background-color:@item.statusservidor_stts">
              @item.statusservidor
          </span>
      </a>
   </p>
</td>

1

Use the @Url.Action it mounts the URL for you dynamically with the passed parameter.

I prefer when creating link using the @Url.Action than the @Url.ActionLink because visually getting easier from someone who does not know the Razor HELPERS understands that there is a link and @Url.Action returns a URL

Browser other questions tagged

You are not signed in. Login or sign up in order to post.