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

前端 未结 2 1468
猫巷女王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:40

    I dont think

    new List {2, 2, 2}
    

    gets properly converted into an POST that is bindable, you want to send

    Ids=1&Ids=2&Ids=3
    

    a comma separate list may also work, im not sure, i don't use the crappy default modelbinder.

    Why are you doing that anyway? I hope thats pseudocode for something else...

提交回复
热议问题