Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions DotnetViewComponents/ViewComponents/SummaryListViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace DotnetViewComponents.ViewComponents
{
using Microsoft.AspNetCore.Mvc;
using DotnetViewComponents.ViewModels;

public class SummaryListViewComponent : ViewComponent
{
public IViewComponentResult Invoke(IEnumerable<SummaryListItemViewModel> summaryListItem,
bool hasBorder = true)
{
var model = new SummaryListViewModel
(
summaryListItem,
hasBorder
);

return View(model);
}
}
}
33 changes: 33 additions & 0 deletions DotnetViewComponents/ViewModels/SummaryListItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace DotnetViewComponents.ViewModels
{
public class SummaryListItemViewModel
{
public SummaryListItemViewModel(
string title,
string description,
string? actionName = null,
string? aspAction = null,
string? aspController = null,
Dictionary<string, string>? aspRouteData = null)
{
Title = title;
Description = description;
ActionName = actionName;
AspAction = aspAction;
AspController = aspController;
AspRouteData = aspRouteData;
}

public string Title { get; set; }

public string Description { get; set; }

public string? ActionName { get; set; }

public string? AspAction { get; set; }

public string? AspController { get; set; }

public Dictionary<string, string>? AspRouteData { get; set; }
}
}
18 changes: 18 additions & 0 deletions DotnetViewComponents/ViewModels/SummaryListViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DotnetViewComponents.ViewModels
{
using System.Collections.Generic;
public class SummaryListViewModel
{
public SummaryListViewModel(
IEnumerable<SummaryListItemViewModel> summaryListItem,
bool hasBorder)
{
SummaryListItem = summaryListItem;
HasBorder = hasBorder;
}

public IEnumerable<SummaryListItemViewModel> SummaryListItem { get; set; }

public bool HasBorder { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@using DotnetViewComponents.ViewModels
@model SummaryListViewModel

@{
bool hasActions = !String.IsNullOrWhiteSpace(@Model.SummaryListItem.First().AspController);
}

<dl class="nhsuk-summary-list @(!Model.HasBorder ? "nhsuk-summary-list--no-border" : "")">
@foreach (var listItem in Model.SummaryListItem)
{
<div class="nhsuk-summary-list__row">
<dt class="nhsuk-summary-list__key">
@listItem.Title
</dt>
<dd class="nhsuk-summary-list__value">
@listItem.Description
</dd>

@if (hasActions)
{
<dd class="nhsuk-summary-list__actions">

<a asp-controller="@listItem.AspController" asp-action="@listItem.AspAction" asp-all-route-data="@listItem.AspRouteData">
@listItem.ActionName<span class="nhsuk-u-visually-hidden"> @listItem.Title</span>
</a>

</dd>
}
</div>
}
</dl>