From 28ea57b3ee75f68b4a3ef35b42cd1e593e8d8d3d Mon Sep 17 00:00:00 2001 From: Chris Hynes Date: Wed, 13 May 2015 10:28:15 -0700 Subject: [PATCH] Allow overriding SetGriddlyDefault via parameter value --- Build/CommonAssemblyInfo.cs | 4 ++-- Griddly.Mvc/GriddlyExtensions.cs | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Build/CommonAssemblyInfo.cs b/Build/CommonAssemblyInfo.cs index 2cf57b8..f82eded 100644 --- a/Build/CommonAssemblyInfo.cs +++ b/Build/CommonAssemblyInfo.cs @@ -15,5 +15,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.1.4")] -[assembly: AssemblyFileVersion("1.1.4")] +[assembly: AssemblyVersion("1.1.5")] +[assembly: AssemblyFileVersion("1.1.5")] diff --git a/Griddly.Mvc/GriddlyExtensions.cs b/Griddly.Mvc/GriddlyExtensions.cs index a9284ec..b0ee9da 100644 --- a/Griddly.Mvc/GriddlyExtensions.cs +++ b/Griddly.Mvc/GriddlyExtensions.cs @@ -107,26 +107,41 @@ public static HtmlString AttributeIf(this HtmlHelper helper, string name, bool s public static void SetGriddlyDefault(this Controller controller, ref T parameter, string field, T value) { if (controller.ControllerContext.IsChildAction) - parameter = value; + { + if (EqualityComparer.Default.Equals(parameter, default(T))) + parameter = value; - controller.ViewData["_griddlyDefault_" + field] = value; + controller.ViewData["_griddlyDefault_" + field] = parameter; + } + else + controller.ViewData["_griddlyDefault_" + field] = value; } public static void SetGriddlyDefault(this Controller controller, ref T[] parameter, string field, IEnumerable value) { if (controller.ControllerContext.IsChildAction) - parameter = value.ToArray(); + { + if (parameter == null) + parameter = value.ToArray(); - controller.ViewData["_griddlyDefault_" + field] = value; + controller.ViewData["_griddlyDefault_" + field] = parameter; + } + else + controller.ViewData["_griddlyDefault_" + field] = value; } public static void SetGriddlyDefault(this Controller controller, ref T?[] parameter, string field, IEnumerable value) where T : struct { if (controller.ControllerContext.IsChildAction) - parameter = value.Cast().ToArray(); + { + if (parameter == null) + parameter = value.Cast().ToArray(); - controller.ViewData["_griddlyDefault_" + field] = value; + controller.ViewData["_griddlyDefault_" + field] = parameter; + } + else + controller.ViewData["_griddlyDefault_" + field] = value; } public static object GetGriddlyDefault(this WebViewPage page, string field)