शेखर
शेखर

Reputation: 17614

Posting List<Object> to a webapi 2

I have created a webapi as follow

 public OatherResponse Post([FromBody] List<Oather> oather)
 {

Note that OatherResponse and Oather both are classes having some property.
Now I am trying to test this using simple html as below

<form method="post" action="http://localhost:50813/api/RegisterOather">
    <input type="text" name="oather[0].OatherName" id="oather[0].OatherName" value="a3VsZGVlcA==" />
    <input type="text" name="oather[1].OatherName" id="oather[1].OatherName" value="a3VsZGVlcA==" />
    <input type="submit" value="Click Here" />
</form>

OatherName is a string property in Oather class. But I always get count of oather as zero.

Am I missing something.

Upvotes: 0

Views: 52

Answers (1)

user3559349
user3559349

Reputation:

The name attribute values should be

name="[0].OatherName"
name="[1].OatherName"

Upvotes: 1

Related Questions