asp.net web api - MVC Web API post an array of integers via x-www-form-encoded -
i trying thought simple. have html form posts set of integer inputs, called "level":
<form action="/api/levels" method="post"> <input name="level" value="10" /> <input name="level" value="20" /> <input name="level" value="30" /> <button type="submit">submit</button> </form>
i trying receive mvc web api controller method this:
public void post(int[] level) { }
diagnosing chrome's network tools confirms request contains form info expect:
level=10&level=20&level=30
the problem level parameter null. want array 3 elements of values 10, 20 , 30.
there many posts similar things, can't find talks web api model binding rather mvc, or seem complaining changes made in older versions release candidates.
can point me in right direction please?
if want body level=10&level=20&level=30
bound, need action method parameter so.
public httpresponsemessage post(myclass c) { // utilize c.level array here } public class myclass { public int[] level { get; set; } }
instead, if want action method parameter int[] level
, http message must so.
post http://server/api/levels http/1.1 content-type: application/x-www-form-urlencoded content-length: 11 =10&=20&=30
for this, have form so.
<form action="/api/levels" method="post"> <input name="" value="10" /> <input name="" value="20" /> <input name="" value="30" /> <button type="submit">submit</button> </form>
the reason weirdness asp.net web api binds entire body 1 parameter.
asp.net-web-api
No comments:
Post a Comment