I have a list of skills which I wish to display endorsers for , to achieve this I decided to post the ID using an HTML Action Link and then retrieve the endorsers within another DIV Class:
The div class which displays all the skills as hyperlinks:
<div class="skill">
@foreach (var skl in model.userskills)
{
@Html.ActionLink(@skl.userskill_content , "Index" , "Home" , new {skl.userskill_id} , null);
</div>
The div class which displays all the endorsers:
<div class="endorsers">
@foreach (var skill in model.endorsers)
{
@skl.user_forename @skil._user_surname
}
</div>
How do I pass the 'new {skl.userskill_id} ' into the controller so this can that each endorser based on this specific userskill_id? So if I click on this hyperlink "C#' skill , it will load a list of endorsers based on the ID of 'C#'.
I hope this is clear as it can be . Thank you
You need to add id=
before the parameter:
@Html.ActionLink(@skl.userskill_content ,
"Index" , "Home" , new {id = skl.userskill_id} , null);
You must also make sure that the controller action is an HTTP get as an ActionLink
will invoke this, and also make sure your controller parameter matches i.e
public ActionResult AnAction(int id)