How do I pass a list of integers to an MVC action?

前端 未结 2 1482
猫巷女王i
猫巷女王i 2020-12-20 17:55

I have an action that depends on a list of integers. My first instinct was to simply declare the action with a List.

I tried declaring the action in the controller

2条回答
  •  半阙折子戏
    2020-12-20 18:33

    Yes. The default model binder can bind "ids" to any ICollection. But you have to submit multiple parameters with the same name. That eliminates using the helper method "ActionLink". You can use url helper Action and append the ids to the link like so:

    ?ids=2&ids=1&ids=3">Test link
    

    Here's the link from Haack's block.

提交回复
热议问题