2

When using multi-value GET parameters like so:

/?param=1&param=2&param=3

You can automatically model-bind to a list, like so:

public ActionResult MyAction(List<int> param)

How can I pass such values using anonymous types, in URL generation?

@Url.Action("MyAction", new { param = ?? })

Using an array / list doesn't work -

@Url.Action("MyAction", new { param = new List<string>{ "1", "2", "3" } })

As it just spits out Object.ToString() like:

?param=System.Collections.Generic.List%601%5BSystem.String%5D

Cheers

Dave Bish
  • 19,263
  • 7
  • 46
  • 63

1 Answers1

1

Not the nice solution your after, buy you could do, assuming you know whether to add the ? or not.

@Url.Action("MyAction")?param=@string.Join("&param=", new [] {1, 2, 3})

Maybe a helper could be written that does this. see URL.Action with a string array?

Community
  • 1
  • 1
Naz
  • 1,793
  • 2
  • 13
  • 25