Search code examples
c#angularjsasp.net-web-apiangular-resourceasp.net-apicontroller

Fetch data from Object type c#


I have a WebAPI controller written in c# which look like this:

public void Post(Object obj)
{

}

Now, using $resource of angularjs I am posting a object like {name: "xyz"} to this controller.

So, obj seems like a object with property "name" and value "xyz" (quotes for clarity). How can I extract the value of the property name from the obj?


Solution

  • The easiest way is to use a DTO so you would have something like this.

    public void Post(MyDTO dto){
      doStuff(dto.name)
    }
    
    public class MyDTO{
       public String name {get;set;}
    }