Skip to content

Commit b68ff4a

Browse files
committed
We use strings for enum values. Apply that to defaults.
1 parent 91f805f commit b68ff4a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,31 @@ public static object GetGriddlyDefault(this WebViewPage page, string field)
201201
public static Dictionary<string, object> GetGriddlyDefaults(this WebViewPage page)
202202
{
203203
Dictionary<string, object> defaults = new Dictionary<string, object>();
204+
204205
foreach (var key in page.ViewData.Keys.Where(k => k.StartsWith("_griddlyDefault_")))
205206
{
206-
defaults[key.Substring("_griddlyDefault_".Length)] = page.ViewData[key];
207+
var value = page.ViewData[key];
208+
string stringValue = null;
209+
210+
Type t = null;
211+
212+
if (value != null)
213+
{
214+
t = value.GetType();
215+
216+
if (t.IsArray)
217+
{
218+
t = t.GetElementType();
219+
220+
if ((Nullable.GetUnderlyingType(t) ?? t).IsEnum)
221+
value = ((Array)value).Cast<object>().Select(x => x?.ToString()).ToArray();
222+
}
223+
224+
if (stringValue == null)
225+
stringValue = value.ToString();
226+
}
227+
228+
defaults[key.Substring("_griddlyDefault_".Length)] = value;
207229
}
208230

209231
return defaults;

0 commit comments

Comments
 (0)