Skip to main content

Posts

Showing posts from February, 2015

WEB API: PASSING A COMPLEX TYPE IN JSON USING J QUERY

In my  project i wanted to pass a complex type to the Post method of an Web Api controller. The Post itself will be done using JQuery in the JSON format. I noticed that the parameter was always null. After a bit of searching i found the solution Server Side code   public class ValuesController : ApiController     {         public class MyComplexType         {             public string Name { get; set; }             public MyComplexSubType MyComplexSubType { get; set; }         }         public class MyComplexSubType         {             public int Age { get; set; }         }         // GET api/<controller>         public IEnumerable<string> Get()         {             return new string[] { "value1", "value2" };         }         // GET api/<controller>/5         public string Get(int id)         {             return "value";         }               // POST api/values         p