Hi I have the following list view grouped by a Name so that I can display that name in the group header.

I want to be able to put a link next to the name to access related information and need to pass it the Id for the Name

@model IEnumerable<YFA.ViewModels.YoungFFContactListViewModel>

<table class="table">
@foreach (var group in Model
.OrderBy(x => x.YoungFFName)
.GroupBy(x => x.YoungFFName))
{
<tr class="group-header">
    <th colspan="12"><h4>@group.Key - @Html.ActionLink("More Details here", "YoungFFDetailsFC", "YoungFF", new { youngFFId = item.YoungFFId}, null)</h4></th>
</tr>
<tr>
    <th>
        @Html.DisplayNameFor(model => model.Name)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.ContactRelationship)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Mobile)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.ContactTelephone)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Work)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.PrimaryContact)
    </th>
</tr>

foreach (var item in group)
{
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Name) @Html.HiddenFor(modelItem => item.YoungFFId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ContactRelationship) @Html.HiddenFor(modelItem => item.YoungFFContactId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Mobile)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.ContactTelephone)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Work)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.PrimaryContact)
    </td>
</tr>
}
}

</table>

The data is passed by this controller

        public ActionResult FCEmergencyContactList(int branchId)
    {
        var youngFFs = db.YoungFFs.Where(x => x.BranchId == branchId && x.Left == null).Select(x => x.YoungFFId);

        //Populate the list
        var contacts = from s in db.YoungFFContacts
                       where youngFFs.Contains(s.YoungFFId)
                       orderby s.LastName
                       select new
                       {
                           Name = s.FirstName + " " + s.LastName,
                           YoungFFId = s.YoungFFId,
                           ContactRelationship = db.ContactRelationships.FirstOrDefault(x => x.ContactRelationshipId == s.ContactRelationshipId).ContactRelationshipName,
                           Telephone = s.Phone,
                           YoungFFContactId = s.YoungFFContactId,
                           PrimaryContact = s.PrimaryContact,
                           Mobile = s.Mobile,
                           Work = s.Work,
                           YoungFFName = db.YoungFFs.FirstOrDefault(x => x.YoungFFId == s.YoungFFId).FirstName + " " + db.YoungFFs.FirstOrDefault(x => x.YoungFFId == s.YoungFFId).LastName,
                       };

        var viewModel = contacts.Select(t => new YoungFFContactListViewModel
        {
            ContactRelationship = t.ContactRelationship,
            ContactTelephone = t.Telephone,
            Name = t.Name,
            PrimaryContact = t.PrimaryContact,
            YoungFFContactId = t.YoungFFContactId,
            YoungFFId = t.YoungFFId,
            Mobile = t.Mobile,
            Work = t.Work,
            YoungFFName = t.YoungFFName,
        });
        return PartialView("_FCEmergencyContactList", viewModel);
    }

How can I access the related Id?

Related posts

Recent Viewed