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?

1 Answer 1

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;}
}
Sign up to request clarification or add additional context in comments.

2 Comments

I know , but I want to fetch data from Object obj.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.