My Html code is something like this.
<input type="text" name="Id" value="123"/>
<input type="text" name="Name" value="XYZ"/>
<input type="text" name="Abc.Address" value="ABC,XYZ 700567"/>
<input type="text" name="Abc.Mobile" value="6958743216"/>
Classes:-
class A
{
public string Id { get; set; }
public string Name { get; set; }
public Abc Abc { get; set; }
}
class Abc
{
public string Address { get; set; }
public string Mobile{ get; set; }
}
Through upper input When I am calling MVC controller the then binding happen. means for following method
public ActionResult Post(A x)
value in x is
x.Id="123"
x.Name="XYZ"
x.Abc.Address="ABC,XYZ 700567"
x.Abc.Mobile="6958743216"
but when I tried same things in web api it is giving me 415(Unsupported media type). means for following method
public IHttpActionResult Post(A x)
instead of binding it is giving 415 status code saying Unsupported Media Type.
I know it is stupid to ask but why this happen? and if I want to do same binding as happen in mvc how can I achieve that?(I don't want to do something like this
--> public IHttpActionResult Post([SomeBinder]A x)
)
Is there way to achieve this or Not?