Skip to content

Commit 1692374

Browse files
committed
Fix array parameter bugs
Add array parameters to example
1 parent 7cb1dc1 commit 1692374

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public static string[] GetFormattedValueByType(object value)
379379
var type = value.GetType();
380380

381381
if (value is IEnumerable enumerable && type != typeof(string))
382-
return enumerable.Cast<object>().Select(x => x.ToString()).ToArray();
382+
return enumerable.Cast<object>().Select(x => x?.ToString()).ToArray();
383383

384384
string stringValue;
385385

@@ -429,7 +429,9 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
429429
values[value.Key] = Convert.ChangeType(value.Value, typeof(DateTime));
430430
else if (t.IsArray || t.IsSubclassOf(typeof(IEnumerable)))
431431
{
432-
arrayVals.Append(string.Join("&", ((IEnumerable)value.Value).Cast<object>().Select(x=> value.Key + "=" + x.ToString())));
432+
if (arrayVals.Length > 0)
433+
arrayVals.Append("&");
434+
arrayVals.Append(string.Join("&", ((IEnumerable)value.Value).Cast<object>().Select(x=> value.Key + "=" + x?.ToString())));
433435
}
434436
}
435437
}

Griddly/Controllers/Examples/ParametersGrid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Griddly.Controllers
99
{
1010
public partial class ExampleController : Controller
1111
{
12-
public GriddlyResult ParametersGrid(string lastname)
12+
public GriddlyResult ParametersGrid(string lastname, long?[] collection)
1313
{
1414
ViewBag.TitleParameter = $"Last Name starts with \"{lastname}\"";
1515

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@Html.Griddly("ParametersGrid", new { lastname = "s" })
1+
@Html.Griddly("ParametersGrid", new { lastname = "s", collection = new long?[] { null } })

0 commit comments

Comments
 (0)