From 8a11d5c0d918264e95ddcdebd7dfa0554bccb216 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 1 Dec 2019 22:24:01 -0500 Subject: fix incorrect link URLs in some cases --- src/SMAPI.Web/Framework/Extensions.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/SMAPI.Web/Framework/Extensions.cs (limited to 'src/SMAPI.Web/Framework') diff --git a/src/SMAPI.Web/Framework/Extensions.cs b/src/SMAPI.Web/Framework/Extensions.cs new file mode 100644 index 00000000..d7707924 --- /dev/null +++ b/src/SMAPI.Web/Framework/Extensions.cs @@ -0,0 +1,28 @@ +using JetBrains.Annotations; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; + +namespace StardewModdingAPI.Web.Framework +{ + /// Provides extensions on ASP.NET Core types. + public static class Extensions + { + /// Get a URL with the absolute path for an action method. Unlike , only the specified are added to the URL without merging values from the current HTTP request. + /// The URL helper to extend. + /// The name of the action method. + /// The name of the controller. + /// An object that contains route values. + /// The generated URL. + public static string PlainAction(this IUrlHelper helper, [AspMvcAction] string action, [AspMvcController] string controller, object values = null) + { + RouteValueDictionary valuesDict = new RouteValueDictionary(values); + foreach (var value in helper.ActionContext.RouteData.Values) + { + if (!valuesDict.ContainsKey(value.Key)) + valuesDict[value.Key] = null; // explicitly remove it from the URL + } + + return helper.Action(action, controller, valuesDict); + } + } +} -- cgit