<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How Do I: Return JSON Formatted Data for an AJAX Call in an ASP.NET MVC Web Application?</title><link>http://asp.net</link><pubDate>Sun, 06 Feb 2011 16:41:04 GMT</pubDate><generator>umbraco</generator><description>Comments for How Do I: Return JSON Formatted Data for an AJAX Call in an ASP.NET MVC Web Application?</description><language>en</language><atom:link href="http://asp.net/rss/comments/27489" rel="self" type="application/rss+xml" /><item><title>Comment Posted by dewey2009</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Fri, 23 Oct 2009 15:46:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007558</guid><description><![CDATA[ <p>Here are two things to be aware of:</p><p></p><p>1)  You&#39;ll need to define a class in the Models folder.</p><p></p><p>  public class Customer</p><p>  {</p><p></p><p>    public string CustomerName { get; set; }</p><p>    public string City { get; set; }</p><p></p><p>  }</p><p></p><p>2)  This video works with VS 2008/MVC 1.  If you are using MVC 2 or Visual Studio 2010 Beta 2, then you&#39;ll need to make a slight adjustment.</p><p></p><p>// MVC 1 code</p><p></p><p>    public JsonResult GetCustomer()</p><p>    {</p><p>      Models.Customer customer = new Models.Customer();</p><p>     </p><p>      customer.CustomerName = &quot;Microsoft&quot;;</p><p>      customer.City = &quot;Redmond&quot;;</p><p>     </p><p>      return Json(customer);</p><p>    }</p><p></p><p>// MVC 2 or VS 2010 Beta 2 code</p><p>    public JsonResult GetCustomer()</p><p>    {</p><p>      Models.Customer customer = new Models.Customer();</p><p>     </p><p>      customer.CustomerName = &quot;Microsoft&quot;;</p><p>      customer.City = &quot;Redmond&quot;;</p><p>     </p><p>      return Json(mc, JsonRequestBehavior.AllowGet);</p><p>    }</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/dewey2009.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by gardavis</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Fri, 23 Oct 2009 16:44:02 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007559</guid><description><![CDATA[ <p>&gt;   return Json(mc, JsonRequestBehavior.AllowGet);</p><p></p><p>Do you mean this?: </p><p></p><p>   return Json(customer, JsonRequestBehavior.AllowGet);</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/gardavis.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by dewey2009</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Fri, 23 Oct 2009 17:19:52 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007560</guid><description><![CDATA[ <p>Gardavis,</p><p></p><p>Thanks for the correction.  I forgot to change mc to customer.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/dewey2009.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by rafek</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Sat, 24 Oct 2009 05:25:40 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007561</guid><description><![CDATA[ <p>Short but helpfull video, thanks. </p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/rafek.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by gerrylowry</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Thu, 12 Nov 2009 02:29:55 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007562</guid><description><![CDATA[ <p>&quot;Chris Pels shows how to use the JsonResult and Json classes to return instances of classes as JSON formatted data.&quot;</p><p></p><p>(1) a transcript of each video would be useful.</p><p></p><p>(2) assuming that these videos are for BEGINNERs too,</p><p>    it would be a very good idea to briefly say </p><p>    (a) what JSON is, and</p><p>    (b) when and why one might use JSON.</p><p></p><p><a rel="nofollow" href="http://json.org/" target="_blank">json.org/</a></p><p>&quot;JSON (JavaScript Object Notation) is a lightweight data-interchange format.</p><p>... easy for humans to read and write.</p><p>... easy for machines to parse and generate.</p><p>... based on a subset of the JavaScript ...</p><p>JSON is a text format that is completely language independent ...</p><p> ... JSON an ideal data-interchange language.&quot;</p><p></p><p>It is important in learning materials to explain &quot;why&quot; and not just &quot;how&quot;; example, in the sixth minute, Chris talks about a JSON function and an object in JSON format without explaining either.  In the seventh minute, Chris say &quot;Let&#39;s use jQuery ...&quot; without saying why jQuery* instead of for example, just JavaScript.</p><p></p><p>  *jQuery [<a rel="nofollow" href="http://jquery.com/]" target="_blank">jquery.com/</a> &quot;... a fast and concise JavaScript Library ...&quot;</p><p></p><p>There is an ancient and well worn teaching paradigm that is seldom used in Microsoft videos:</p><p>(a) tell the student the lesson plan and goals</p><p>(b) deliver (a)</p><p>(c) recapitulate (b)</p><p></p><p></p><p>Regards,</p><p>Gerry (Lowry)</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/gerrylowry.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by srieen</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Wed, 23 Dec 2009 15:27:25 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007563</guid><description><![CDATA[ <p>Well said Gerry</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/srieen.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by srvking</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Wed, 20 Jan 2010 11:10:27 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007564</guid><description><![CDATA[ <p>Totally Agree with Gerry ... </p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/srvking.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by gangelo</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Thu, 11 Mar 2010 21:02:27 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000007565</guid><description><![CDATA[ <p>Is it me, or does the piece of crap C# project get a &quot;Line: 16</p><p>Error: Object expected&quot; error when choosing the Customer menu item?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/gangelo.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by jamesguo</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Sun, 25 Jul 2010 18:22:35 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009604</guid><description><![CDATA[ <p>Eery nice. The JQuery calls to get the Json objects solve the same problems in web forms where plain javascrpt calls are used to call web methods on the pages. But this provides more controls to the developers and the server methods are not limited to static web methods.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/jamesguo.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by cyhcyhhychyc</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Tue, 24 Aug 2010 02:05:38 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000009963</guid><description><![CDATA[ <p>can jquery do all the things that ajaxpro can? Do we have to use jquery or ms ajax to acquire ajax ability?</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/cyhcyhhychyc.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by deviantseev</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Wed, 01 Sep 2010 12:22:54 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010086</guid><description><![CDATA[ <p>I would like to point out that dewey2009 does not resolve the underlying problem. There is a reason that MVC2 by default disables the ability to return JSON data through an ajax get call. It introduces a big security vulnerability. So, if you care about the security and privacy of the specific data that is being returned, don&#39;t use the JsonRequestBehavior.AllowGet override. Instead, only use the ajax post method to call the function.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/deviantseev.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by makerofthings7</title><link>http://asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application</link><pubDate>Sun, 06 Feb 2011 16:41:04 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000011951</guid><description><![CDATA[ <p>Information on using JSON with HTTP GET... both the security risks, mitigations, and potential work arounds <a rel="nofollow" href="http://stackoverflow.com/questions/4914994/using-mvc3s-antiforgerytoken-in-http-get-to-avoid-javascript-csrf-vulnerability" target="_blank">stackoverflow.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/makerofthings7.jpg?forceidenticon=false&amp;dt=635044954200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>