How to post an empty array (of ints) (jQuery -> MVC 3)

后端 未结 2 1742
自闭症患者
自闭症患者 2021-01-12 08:02

Using jQuery I am posting an array of int to my MVC 3 application by putting the array in the data parameter like so: data: { myIntArray: myIntArray }

2条回答
  •  臣服心动
    2021-01-12 08:13

    Just in case anyone lands on this question trying to resolve this...

    This is a bug in MVC (that still exists in MVC 4 in 2019, duh):

    • when you POST an empty form parameter into an action method that has an array-mapped variable or model - this results in an 1-element zero array { 0 }.

    I found no other way than to deal with it on the back-end.

    Here's another question discussing it: ASP.NET MVC Int Array parameter with empty array defaults to {0}

提交回复
热议问题