0

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?

drew_w
  • 10,320
  • 4
  • 28
  • 49
mdnajimahmed
  • 124
  • 2
  • 9

1 Answers1

1

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;}
}
Zipper
  • 7,034
  • 8
  • 49
  • 66
  • I know , but I want to fetch data from Object obj. – mdnajimahmed Feb 24 '15 at 06:08
  • 1
    Then I would use a dictionary, that should work for what you want, although I would say if you're sending up random objects you're probably doing something wrong. – Zipper Feb 24 '15 at 16:28