Click here to Skip to main content
15,910,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
is it possible to create json object in the controller,If possible,
can u provide sample code to create json in the controller
Posted

1 solution

Hi,

I hope this question is still opened :)

It seems that you use ASP.NET MVC, right?
If you want to return a Json object directly from your action, you can just write the following:

C#
return new JsonResult { Data = new { Test1 = "asdf", Test2 = "qwer" } };


if you already have a variable containing the data you want to return, you can do it this way:

C#
return new JsonResult { Data = yourDataObject };


Hope this helps.


Best regards and happy coding,
Chris
 
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