summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-01 22:24:01 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-02 20:14:12 -0500
commit8a11d5c0d918264e95ddcdebd7dfa0554bccb216 (patch)
treeebaaa4b647e85789fc5ebd4f8399af3ad29ea73c /src/SMAPI.Web/Framework
parent5f532c259d5d3050bd6a053659067617db136d57 (diff)
downloadSMAPI-8a11d5c0d918264e95ddcdebd7dfa0554bccb216.tar.gz
SMAPI-8a11d5c0d918264e95ddcdebd7dfa0554bccb216.tar.bz2
SMAPI-8a11d5c0d918264e95ddcdebd7dfa0554bccb216.zip
fix incorrect link URLs in some cases
Diffstat (limited to 'src/SMAPI.Web/Framework')
-rw-r--r--src/SMAPI.Web/Framework/Extensions.cs28
1 files changed, 28 insertions, 0 deletions
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
+{
+ /// <summary>Provides extensions on ASP.NET Core types.</summary>
+ public static class Extensions
+ {
+ /// <summary>Get a URL with the absolute path for an action method. Unlike <see cref="IUrlHelper.Action"/>, only the specified <paramref name="values"/> are added to the URL without merging values from the current HTTP request.</summary>
+ /// <param name="helper">The URL helper to extend.</param>
+ /// <param name="action">The name of the action method.</param>
+ /// <param name="controller">The name of the controller.</param>
+ /// <param name="values">An object that contains route values.</param>
+ /// <returns>The generated URL.</returns>
+ 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);
+ }
+ }
+}