@foreach (var item " /> @foreach (var item " /> @foreach (var item "/>

HTML.ActionLink to details page not working

126 Views Asked by At

Hi I'm having trouble working this one out. I want my header to be a link that redirects to the details

<div class="card-columns">
    @foreach (var item in Model)
    {
        <div class="card" style="width:300px">
            <img class="card-img-top" [email protected](modelItem => item.CoverArt) alt="Card image">
            <div class="card-body">
                @Html.ActionLink(modelItem => item.Name, "Details", "Albums", new { /* id=item.PrimaryKey */ }, null)
                <p class="card-text">@Html.DisplayFor(modelItem => item.Info)</p>
                <p class="card-text small">@Html.DisplayFor(modelItem => item.ReleaseDate)</p>
            </div>
        </div>
    }
</div>

I found this on the internet but it throws an error:

'There is no argument given that corresponds to the required forma parameter 'fragment' of 'IHtmlHelper.ActionLink(string, string,.....)'

2

There are 2 best solutions below

0
Jef Vandooren On BEST ANSWER

I used this and it worked:

<a asp-action="Details" asp-route-id="@item.Id">
  <h4 class="card-title">
    @item.Name
  </h4>
</a>
2
Dtrl-01 On

Replace modelItem => item.Name with item.Name

<div class="card-columns">
    @foreach (var item in Model)
    {
        <div class="card" style="width:300px">
            <img class="card-img-top" [email protected](modelItem => item.CoverArt) alt="Card image">
            <div class="card-body">
                @Html.ActionLink(item.Name, "Details", "Albums", new { /* id=item.PrimaryKey */ }, null)
                <p class="card-text">@Html.DisplayFor(modelItem => item.Info)</p>
                <p class="card-text small">@Html.DisplayFor(modelItem => item.ReleaseDate)</p>
            </div>
        </div>
    }
</div>