jquery - Form with Select Multiple Post to WebAPI -


i using c# web api receive post of form have select multiple.

my model in web api method like:

{model: { username: "test", groups: [ {id:123}, {id: 2}]}} 

in other words, model class fields, , array of complex type.

webapi works correctly if form data posted is:

username:test groups[0][id]:123 groups[1][id]:2 

however, if serialize form $(this).serialize() like:

username:test groups[][id]:123 groups[][id]:2 

which webapi doesn't handle correctly.

this defining select as:

<select name="groups[][id]" >...</select> 

i have tried other ways define select, can't accomplish it.

i able workaround building object based on form's elements , passing object ajax instead of $(this).serialize, ugly hack.

does webapi somehow supports receiving properties arrays in model posted form?

thanks.

i had same problem , resolved using https://www.nuget.org/packages/imranb.modelbindingfix

more info: http://weblogs.asp.net/imranbaloch/archive/2012/12/08/fixing-model-the-binding-issue-of-asp-net-mvc-and-asp-net-web-api.aspx


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -