@model (Dictionary Items, int Level) @functions { private bool IsValidURL(string source) { return Uri.TryCreate(source, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); } } @if (Model.Items.Any()) { var hasCart = Model.Items.ContainsKey("Cart"); @if (hasCart || (Model.Items.ContainsKey("Subtotal") && Model.Items.ContainsKey("Total"))) { @if (hasCart) { @foreach (var (key, value) in (Dictionary)Model.Items["Cart"]) { } } @if (Model.Items.ContainsKey("Subtotal")) { } @if (Model.Items.ContainsKey("Discount")) { } @if (Model.Items.ContainsKey("Tip")) { } @if (Model.Items.ContainsKey("Total")) { } } else { foreach (var (key, value) in Model.Items) { @if (value is string str) { if (!string.IsNullOrEmpty(key)) { } } else if (value is Dictionary { Count: > 0 } subItems) { } else if (value is IEnumerable valueArray) { } } }
@key @value
Subtotal @Model.Items["Subtotal"]
Discount @Model.Items["Discount"]
Tip @Model.Items["Tip"]
Total @Model.Items["Total"]
@key@* Explicitely remove whitespace at front here *@@if (IsValidURL(str)){@str}else {@str.Trim()} @{ @if (!string.IsNullOrEmpty(key)) { Write(Html.Raw($"")); Write(key); Write(Html.Raw($"")); } } @{ @if (!string.IsNullOrEmpty(key)) { Write(Html.Raw($"")); Write(key); Write(Html.Raw($"")); } } @foreach (var item in valueArray) { @if (item is Dictionary { Count: > 0 } subItems2) { } else { } }
}