您好我有以下列表视图按名称分组,以便我可以在组头中显示该名称。
我希望能够在名称旁边放置一个链接来访问相关信息,并且需要将其传递给名称的ID
@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>
数据由此控制器传递
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);
}
如何访问相关的ID?