Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to pass a Json object from one controller (one) to another controller (two):

{
"t": "abc",
"r": '0',
"o": "",
"n": "",
"v": "1",
"k": "1.0",
}

in controller two I want to receive that data:

[HttpPost]
public JObject AllReceivedData(Jobject objData)
{

}

How can I send the Json object from controller one to controller two?
Posted
Comments
Jameel VM 3-Jan-14 8:24am    
from where you want to pass the jSon Data to the second controller?can you elaborate your question?
ashuslove 3-Jan-14 23:49pm    
I want to pass json data from one controller to another both controller are from in different project.
[no name] 4-Jan-14 12:59pm    
if the controller exists in another domain than you have to use the full url. lets say,
you are in http://www.application1.com/contact/. now you want to use application2 domain's controller then use full url like http://www.application2.com/contact/add.

Another scenario, if you are in the same domain. then use just "\" at the first to get the rooot's controller.
ashuslove 5-Jan-14 23:41pm    
Thanks for the Help Amir,

I am using different Domain to pass the Json Data Object but what i am not getting is how to send data using URL. What i need to use with URL to POST that objects into another controller.
[no name] 6-Jan-14 1:59am    
try with $.ajax({method:post,url: your url, data:jsonData()})
then it will be converted to your Action's parameter.

1 solution

Finally Got it.

//Get Data in Json Format
client.Headers[HttpRequestHeader.ContentType] = "application/json";

//Sent the Request to URL and Fetch the Data in Bytes
var result = client.UploadData("URL", Encoding.UTF8.GetBytes(request));

//Convert into dynamic object to get Json format
dynamic obj = JObject.Parse(Encoding.UTF8.GetString(result).ToString());

//DeserializeObject the "obj" Object in Any Model.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900