I have encountered a few similar queries on this platform and attempted the suggested solutions, but unfortunately, they did not resolve my specific issue.
Within my view, I am using @Html.DisplayFor
in a Foreach
loop to display all GroupIDs in a particular section. However, instead of displaying them as "1 2 3 4 5", they appear as a single string "12345".
The problem lies in the second row of the table (
@Html.DisplayFor(model => item.Group)
) where there is an issue with the expand/collapse functionality.
View
<table>
<tbody>
@foreach (var item in Model)
{
<tr>
<td class="col-md-1">+</td>
<td class="col-md-2">@Html.DisplayFor(model => item.Name)</td>
</tr>
<tr>
<td class="col-md-1" colspan="3"><p style="display:none">@Html.DisplayFor(model => item.Group)</p></td>
</tr>
}
</tbody>
</table>
I have created a simple JSFiddle below for better visualization of the issue at hand. Thank you in advance for your assistance, and feel free to ask for more information if needed. JSFiddle
EDIT Below is the controller code added to demonstrate what 'Group' entails.
public ActionResult SectionTable()
{
Manager manager = new Manager();
var data3 = manager.GetAllSections();
var groups = manager.GetAllGroups();
var sectionDetails = from u in data3
select new SectionDetail
{
SectionID = u.Id,
Name = u.Name,
Description = u.Description,
Group = (from g in groups
where g.SectionId == u.Id
select new GroupDetail() { GroupID = g.Id, GroupDescription = g.Description, GroupName = g.Name, GroupSectionID = g.SectionId, Rights = g.Rights, RightsID = g.RightsId, SectionName = g.SectionName }).ToList()
};
return View(sectionDetails.ToList());
}