Question

Is there a way to get this working:

@foreach (var item in Model.CategoryListByKeywordsDetails)
{
    <li>
        @Html.ActionLink("ver >", MVC.Ad.ListByCategory(item.Id, (string)ViewBag.keywords))
        {
            <em>@Html.DisplayFor(modelItem => item.SearchCount)</em> @Html.DisplayFor(modelItem => item.Name) <span class="float-right">ver ></span>
        }
    </li>
}        

I want the result (I put spaces to show the HTML code):

<a href="/Ad/ListByCategory?categoryId=1&keywords=alfa">
    <em>6</em>Carros
    <span class="float-right">ver &gt;</span>
</a>
Was it helpful?

Solution

You can't do it with any of the @Html.ActionLink overloads. Use @Url.Action inside an a tag:

<a href="@Url.Action(MVC.Ad.ListByCategory(item.Id, (string)ViewBag.keywords))">
    <em>@Html.DisplayFor(modelItem => item.SearchCount)</em> @Html.DisplayFor(modelItem => item.Name) 
    <span class="float-right">ver &gt;</span>
</a>

OTHER TIPS

I think your problem is including some HTML codes inside an action link. You could simply use an "a" tag:

    @foreach (var item in Model.CategoryListByKeywordsDetails)
    {
        <li>
          <a href="@Url.Action(MVC.Ad.ListByCategory(item.Id, (string)ViewBag.keywords))">                
                    <em>@item.SearchCount</em>@item.Name<span class="float-right">ver &gt;</span>
          </a>
        </li>
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top