.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How To Use JsonResult

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
I'm learning about controller action methods in MVC and I'm doing a how-totutorial so I can understand how to use JsonResult. My setup is simple. I have asingle view, Start.aspx. I have a query string and when the id is 1, it loadsthe view for the Start.aspx page. When the query string is 2, it loads aJsonResult.// Markup from Start.aspx<ul>    <li><a href="Home/Start?id=1">Click to see a ViewResult</a></li>    <li><a href="Home/Start?id=2">Click to see a JsonResult</a></li></ul>// Code from HomeController.cspublic ActionResult Start(){    switch (Convert.ToInt32(Request.QueryString["id"]))    {        case 1: return View();        case 2: return Json(new Dictionary<string, string> { { "1", "Blue" }, { "2", "Yellow" }, { "3", "Green" } }, JsonRequestBehavior.AllowGet);        default: return View();    }}When I click on the "Click to see a JsonResult" link, a new JSON object is sentback to the client and I get a popup in my browser asking me if I want to savethe results, which are:{"1":"Blue","2":"Yellow",

View Complete Post

More Related Resource Links

how to read raw jsonresult output in MVC

its retuHello, How can i get to see the raw jsonresult of an action in a controller? i want to make sure its returning correctly formed data.   thanks

JsonResult and extjs JsonStore

 Hello all, I am trying to use the JsonResult to populate a extjs grid using the extjs JsonStore. The JsonStore requires the json to be formatted in a specific way which I have been unable to make happen. The JsonStore requires the json to be formatted like this.{ results: 2, rows: [ { id: 1, firstname: 'Bill', occupation: 'Gardener' }, // a row object { id: 2, firstname: 'Ben' , occupation: 'Horticulturalist' } // another row object ]} I'm using a linq to sql query to get the data and then I'm passing the linq variable to the Controller.Json method as the return type. What this gives me is the following.[{"Code":0,"Label":"Not Processed"},{"Code":1,"Label":"Wish List"},{"Code":2,"Label":"Review Soon"},{"Code":3,"Label":"Subsequent Release"},{"Code":4,"Label":"Scheduled for Release"},{"Code":5,"Label":"Immediate Build/Patch"},{"Code":8,"Label":"Refused"},{"Code":9,"Label":"Non-Problem"}]I'm missing the results: and rows: properties. The only way I can think of to add the results: and rows: properties is to serialize the linq variable to create a string

using jsonresult actions to pass json data to 3rd party apps



i want to use MVC 2 actions to pass JSON data to a 3rd party application via a URL.

The URL will be in the form of http://www.abc.com/controller/action..I am using JSonResult

How can i test the output of this URL to ensure the JSON is properly formed..


must my URL be in the format http://www.abc.com/controller/action.json?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend