From 7bbbe494d5a44b9ee06a5e53bbee76110718a68e Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 15 Apr 2024 11:56:52 -0700 Subject: [PATCH] Avoid throwing null exception Fix #15752 --- .../Views/NavigationItemLink-admin.cshtml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml index a7e8ae2bb81..0fdbba383a2 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/NavigationItemLink-admin.cshtml @@ -7,23 +7,26 @@ TagBuilder tag = Tag(Model, "a"); tag.Attributes["id"] = null; - tag.Attributes["href"] = Model.Href; - if (Model.Href.ToString() == "#") + if (Model.Href == null || Model.Href.ToString() == "#") { tag.Attributes["href"] = "#m" + Model.GetHashCode().ToString(); } + else + { + tag.Attributes["href"] = Model.Href; + } var prefix = "icon-class-"; - // Extract classes that are not icons from Model.Classes + // Extract classes that are not icons from Model.Classes. var notIconClasses = ((IEnumerable)Model.Classes) - .ToList() - .Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)); + .Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) + .ToArray(); - if (notIconClasses.Count() > 0) + if (notIconClasses.Length > 0) { - tag.Attributes["class"] = string.Join(" ", notIconClasses); + tag.Attributes["class"] = string.Join(' ', notIconClasses); } tag.AddCssClass("item-label d-flex");