Reputation: 789
I'm working on asp.Net MVC4 project, and I need to create ActionLink
for each element of a list.
Here is what I have done:
<div class="display-field" id="kalamsDiv">
@foreach(Elections.Domain.Models.Kalam kalam in Model.Kalams)
{
Html.ActionLink(@kalam.Name, "Details", "Kalam", @kalam.KalamID, "");
<br />
}
</div>
And in the model of the view I have a list of "Kalam" object:
public virtual ICollection<Kalam> Kalams { get; set; }
But I'm not seeing any ActionLink
, the div is empty, I can only see the line breaks : <br />
.
What is the mistake I'm making?
Thanks :)
Upvotes: 0
Views: 290
Reputation: 38478
Use @
before Html.ActionLink and remove them before kalam
variable. Create an anonymous object for routeValues
and pass null for htmlAttributes
.
<div class="display-field" id="kalamsDiv">
@foreach(Elections.Domain.Models.Kalam kalam in Model.Kalams)
{
@Html.ActionLink(kalam.Name, "Details", "Kalam", new { ID = kalam.KalamID }, null);
<br />
}
</div>
Upvotes: 1