json - Correct way to pass string array member to MVC WebApi controller -


i'm starting angularjs , trying pass json object strings array member mvc webapi method, cannot let webapi controller receive correct value it. i'm missing obvious, suggest solution? in js, call like:

$http({     url: "/api/test",     method: "get",     params: {       //...         fields: ["one", "two"]     }}); 

on server side, here corresponding model:

public sealed class mymodel {     //...     public list<string> fields { get; set; } } 

and controller's signature:

public dynamic get([fromuri] mymodel model) 

when inspect model, find fields array 1 item, right "raw" json string, e.g. contains ["one","two"] (square brackets , quotes included), rather array 2 items 1 , two. possible fix this? thanx!

try creating client side javascript model object 1 field 'fields' of type array , set fields.

var myobj = {} myobj.fields = []; myobj.fields.push("one") myobj.fields.push("two")  

then pass object method of webapi.

$http({ url: "/api/test", method: "get", data: myobj}); 

i think , should work.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -