Skip to content

Commit 28ea57b

Browse files
committed
Allow overriding SetGriddlyDefault via parameter value
1 parent 33bef44 commit 28ea57b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Build/CommonAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.1.4")]
19-
[assembly: AssemblyFileVersion("1.1.4")]
18+
[assembly: AssemblyVersion("1.1.5")]
19+
[assembly: AssemblyFileVersion("1.1.5")]

Griddly.Mvc/GriddlyExtensions.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,41 @@ public static HtmlString AttributeIf(this HtmlHelper helper, string name, bool s
107107
public static void SetGriddlyDefault<T>(this Controller controller, ref T parameter, string field, T value)
108108
{
109109
if (controller.ControllerContext.IsChildAction)
110-
parameter = value;
110+
{
111+
if (EqualityComparer<T>.Default.Equals(parameter, default(T)))
112+
parameter = value;
111113

112-
controller.ViewData["_griddlyDefault_" + field] = value;
114+
controller.ViewData["_griddlyDefault_" + field] = parameter;
115+
}
116+
else
117+
controller.ViewData["_griddlyDefault_" + field] = value;
113118
}
114119

115120
public static void SetGriddlyDefault<T>(this Controller controller, ref T[] parameter, string field, IEnumerable<T> value)
116121
{
117122
if (controller.ControllerContext.IsChildAction)
118-
parameter = value.ToArray();
123+
{
124+
if (parameter == null)
125+
parameter = value.ToArray();
119126

120-
controller.ViewData["_griddlyDefault_" + field] = value;
127+
controller.ViewData["_griddlyDefault_" + field] = parameter;
128+
}
129+
else
130+
controller.ViewData["_griddlyDefault_" + field] = value;
121131
}
122132

123133
public static void SetGriddlyDefault<T>(this Controller controller, ref T?[] parameter, string field, IEnumerable<T> value)
124134
where T : struct
125135
{
126136
if (controller.ControllerContext.IsChildAction)
127-
parameter = value.Cast<T?>().ToArray();
137+
{
138+
if (parameter == null)
139+
parameter = value.Cast<T?>().ToArray();
128140

129-
controller.ViewData["_griddlyDefault_" + field] = value;
141+
controller.ViewData["_griddlyDefault_" + field] = parameter;
142+
}
143+
else
144+
controller.ViewData["_griddlyDefault_" + field] = value;
130145
}
131146

132147
public static object GetGriddlyDefault(this WebViewPage page, string field)

0 commit comments

Comments
 (0)