0

I need to have method in web api that receives json, but its structure is dynamic. I tried to use following code, but always value is null.

[HttpPost]
public class TestController : Controller
{
   public JsonResult DoJob(dynamic value)
    {
       //Work with parameter
    }     
}

Used this json

{"testObject":{"property":"value"}, "otherPropery": "otherValue"}

UPDATE: This is how I send request from client side

value is {"testObject":{"property":"value"}, "otherPropery": "otherValue"}
$http.post("test/dojob",value);
3
  • how do you call Test/DoJob url? Commented Oct 8, 2015 at 14:46
  • /test/dojob. I have redifined default url without 'api' in it. Commented Oct 8, 2015 at 14:49
  • show the javascript code Commented Oct 8, 2015 at 15:04

2 Answers 2

2

Parameters of controller action methods are bound by their names:

var value = { "value": {
  "testObject": { "property": "value" }, 
  "otherPropery": "otherValue"
} };
$http.post("test/dojob",value);
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, that was the case. Thank you
1

I think, json result it's equivalent to string if you do

[HttpPost]
public class TestController : Controller
{
   public JsonResult DoJob(string value)
    {
       //Work with parameter
    }     
}

it should work

3 Comments

Still the same, value parameter is null.
how do you call to controller?
I use angular http service, I will add how I call api from javascript side

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.