<?xml version="1.0" encoding="UTF-8"?>
<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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PeterKellner.net &#187; MVC</title>
	<atom:link href="http://peterkellner.net/category/aspnet-35/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focussed, JavaScript (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Tue, 07 Feb 2012 21:14:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Meetup At Sencha Headquarters Tomorrow (Tuesday 8/23) in Redwood City Talking MVC in JavaScript!</title>
		<link>http://peterkellner.net/2011/08/22/meetup-at-sencha-headquarters-tomorrow-tuesday-823-in-redwood-city-talking-mvc-in-javascript/</link>
		<comments>http://peterkellner.net/2011/08/22/meetup-at-sencha-headquarters-tomorrow-tuesday-823-in-redwood-city-talking-mvc-in-javascript/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 00:21:50 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Code Camp]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/22/meetup-at-sencha-headquarters-tomorrow-tuesday-823-in-redwood-city-talking-mvc-in-javascript/</guid>
		<description><![CDATA[Tomorrow night (Tuesday, August 23rd), we are having another meetup to talk about using MVC inside of Sencha’s JavaScript products.&#160; I (Peter Kellner) will be talking for the first 20 minutes about how we are integrating the MVC pattern in our Silicon Valley Code Camp web site, then Ed Spencer from Sencha will follow on [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow night (Tuesday, August 23rd), we are having another meetup to talk about using <a href="http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/guide/application_architecture">MVC</a> inside of <a href="http://www.sencha.com/">Sencha’s</a> JavaScript products.&#160; I (Peter Kellner) will be talking for the first 20 minutes about how we are integrating the MVC pattern in our <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp web site</a>, then Ed Spencer from Sencha will follow on talking a lot more about MVC and best practices as well as Q&amp;A</p>  <p>Hope you can make it.&#160; Details are here:</p>  <p><a title="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/28760211/" href="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/28760211/">http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/28760211/</a></p>  <p>&#160;</p>  <p><a href="http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/events/28760211/"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/wp/wp/wp-content/uploads/2011/08/image3.png" width="640" height="388" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/22/meetup-at-sencha-headquarters-tomorrow-tuesday-823-in-redwood-city-talking-mvc-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DevConnections Presentation Orlando, How To Make Your Browser fly</title>
		<link>http://peterkellner.net/2011/03/29/devconnections-presentation-orlando-how-to-make-your-browser-fly/</link>
		<comments>http://peterkellner.net/2011/03/29/devconnections-presentation-orlando-how-to-make-your-browser-fly/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 21:08:27 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Presentations]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/03/29/devconnections-presentation-orlando-how-to-make-your-browser-fly/</guid>
		<description><![CDATA[(About 100 People)  The Presentation was broken down into three parts.&#160;   Part 1  Created a windows razor project that cached in image on a web site using best practices for threading and locking.&#160; The code and project to do this are below:     var downloadByteArray = HttpContext.Current.Cache[cacheName] as [...]]]></description>
			<content:encoded><![CDATA[<p>(About 100 People)</p>  <p>The Presentation was broken down into three parts.&#160; </p>  <h2>Part 1</h2>  <p>Created a windows razor project that cached in image on a web site using best practices for threading and locking.&#160; The code and project to do this are below:</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">var downloadByteArray = HttpContext.Current.Cache[cacheName] <span style="color: #0000ff">as</span> <span style="color: #0000ff">byte</span>[];<br /> <span style="color: #0000ff">if</span> (downloadByteArray == <span style="color: #0000ff">null</span>)<br /> {<br />     <span style="color: #008000">// make sure multiple requestors are not filling up the cache</span><br />     <span style="color: #0000ff">lock</span> (LockVal)<br />     {<br />         downloadByteArray = HttpContext.Current.Cache[cacheName] <span style="color: #0000ff">as</span> <span style="color: #0000ff">byte</span>[];<br />         <span style="color: #0000ff">if</span> (downloadByteArray == <span style="color: #0000ff">null</span>)<br />         {<br />             Thread.Sleep(sleep * 1000);<br /><br />             <span style="color: #0000ff">string</span> imageLocation = HttpContext.Current.Server.MapPath(<span style="color: #006080">&quot;~&quot;</span>) + imageUrl;<br /><br />             downloadByteArray = File.ReadAllBytes(imageLocation);<br />             <span style="color: #0000ff">if</span> (cacheExpiresSeconds &gt; 0)<br />             {<br />                 HttpContext.Current.Cache.Insert(cacheName, downloadByteArray,<br />                                                  <span style="color: #0000ff">null</span>,<br />                                                  DateTime.Now.Add(<span style="color: #0000ff">new</span> TimeSpan(0, 0, 0, cacheExpiresSeconds)),<br />                                                  TimeSpan.Zero, CacheItemPriority.NotRemovable, <span style="color: #0000ff">null</span>);<br />                 CacheInsertCounter = 9999; <span style="color: #008000">// any touch of this increments the global counter</span><br />             }<br />         }<br />     }<br /> }</pre>

  <br /></div>

<p>&#160;</p>

<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:2267f0db-4ee6-46f0-8cec-12de6f76545d" class="wlWriterEditableSmartContent"><p><div><a href="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/WebFormsPreSprite.zip" target="_self">WebFormsPreSprite.zip</a></div></p></div>

<p>&#160;</p>

<h2>Part 2</h2>

<p>Tips from Steve Souders</p>

<p>&#160;</p>

<h2>Part 3</h2>

<p>Sprite Library from Microsoft Example:&#160; <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:62dccea0-5635-435b-b07a-d12f2bec4e7e" class="wlWriterEditableSmartContent"><p><div><a href="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/WebFormsPreSprite_3.zip" target="_self">WebFormsPreSprite.zip</a></div></p></div>
</p>

<p>&#160;</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/image_thumb.png" width="312" height="451" /></a><a href="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/IMAG0174.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="IMAG0174" border="0" alt="IMAG0174" src="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/IMAG0174_thumb.jpg" width="148" height="244" /></a><a href="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/IMAG0177.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="IMAG0177" border="0" alt="IMAG0177" src="http://peterkellner.net/FilesForWebDownload/DevConnections-Presentation_EE06/IMAG0177_thumb.jpg" width="244" height="148" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/03/29/devconnections-presentation-orlando-how-to-make-your-browser-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC3 Unable To Return Large JSON Even with Web Config Patch, Using LargeJsonResult Instead</title>
		<link>http://peterkellner.net/2011/03/21/mvc3-unable-to-return-large-json-even-with-web-config-patch-using-largejsonresult-instead/</link>
		<comments>http://peterkellner.net/2011/03/21/mvc3-unable-to-return-large-json-even-with-web-config-patch-using-largejsonresult-instead/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 18:11:25 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/03/21/mvc3-unable-to-return-large-json-even-with-web-config-patch-using-largejsonresult-instead/</guid>
		<description><![CDATA[I’m trying to download a base64 encoded image that is about 4 Megabytes embedded inside a JSON object.&#160; When I first tried this from my MVC3 Web application, I got the error:     Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on [...]]]></description>
			<content:encoded><![CDATA[<p>I’m trying to download a base64 encoded image that is about 4 Megabytes embedded inside a <a href="http://json.org/">JSON</a> object.&#160; When I first tried this from my <a href="http://www.asp.net/mvc/mvc3">MVC3 Web application</a>, I got the error:</p>  <blockquote>   <h4><i>Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.</i></h4> </blockquote>  <p>&#160;</p>  <span id="more-1450"></span>  <p>I then tried to set the web.config property that everyone seems to reference on the web as follows:</p>  <p>&#160;</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">system.web.extensions</span><span style="color: #0000ff">&gt;</span> <br />    <span style="color: #0000ff">&lt;</span><span style="color: #800000">scripting</span><span style="color: #0000ff">&gt;</span> <br />        <span style="color: #0000ff">&lt;</span><span style="color: #800000">webServices</span><span style="color: #0000ff">&gt;</span> <br />            <span style="color: #0000ff">&lt;</span><span style="color: #800000">jsonSerialization</span> <span style="color: #ff0000">maxJsonLength</span><span style="color: #0000ff">=&quot;2147483645&quot;</span> <span style="color: #ff0000">recursionLimit</span><span style="color: #0000ff">=&quot;100&quot;</span><span style="color: #0000ff">&gt;</span> <br />            <span style="color: #0000ff">&lt;/</span><span style="color: #800000">jsonSerialization</span><span style="color: #0000ff">&gt;</span> <br />        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">webServices</span><span style="color: #0000ff">&gt;</span> <br />        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">scripting</span><span style="color: #0000ff">&gt;</span> <br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">system.web.extensions</span><span style="color: #0000ff">&gt;</span> <br /><br /></pre>

  <br /></div>

<p>However, I kept getting the same error over and over.&#160; So, I used the technique suggested in this article</p>

<p><a title="http://thoughtfulcode.wordpress.com/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/" href="http://thoughtfulcode.wordpress.com/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/">http://thoughtfulcode.wordpress.com/2011/01/03/custom-jsonresult-class-for-asp-net-mvc-to-avoid-maxjsonlength-exceeded-exception/</a></p>

<p>by <a href="http://thoughtfulcode.wordpress.com/about/">Brian Reiter</a> to create an override of the JsonResult class.&#160; That actually worked for me, however unfortunately, it does not show the shape of the data that is currently being returned by MVC3.&#160; That is, MVC3 currently returns a JsonResult as follows:</p>

<p>&#160;</p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">return</span> Json(<span style="color: #0000ff">new</span><br />{<br />    total = blobs.Count,<br />    data = blobs.ToList()<br />}, JsonRequestBehavior.AllowGet);</pre>
</div>

<div>&#160;</div>

<div>Brian suggest in his article to return his LargeJsonResult, do the following:</div>

<div>&#160;</div>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> LargeJsonResult() { Data = output, MaxJsonLength = <span style="color: #0000ff">int</span>.MaxValue };<br /></pre>
</div>

<div>&#160;</div>

<div>This does not quite work for what I want.&#160; For my result to work, I needed to modify the result a little and return it as follows:</div>

<div>&#160;</div>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">return</span><br />   <span style="color: #0000ff">new</span> LargeJsonResult<br />       {<br />           MaxJsonLength = 20000000,<br />           JsonRequestBehavior = JsonRequestBehavior.AllowGet,<br />           Data = <span style="color: #0000ff">new</span><br />                      {<br />                          total = blobs.Count,<br />                          data = blobs.ToList()<br />                      }<br />       };</pre>

  <br /></div>

<div>&#160;</div>

<div>Not much different, but does solve my problem.</div>

<div>&#160;</div>

<div>Thanks Brian for the nice contribution! 
  <br /></div>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/03/21/mvc3-unable-to-return-large-json-even-with-web-config-patch-using-largejsonresult-instead/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing NuGet on VS2010 (first blood)</title>
		<link>http://peterkellner.net/2011/03/02/installing-nuget-on-vs2010-first-blood/</link>
		<comments>http://peterkellner.net/2011/03/02/installing-nuget-on-vs2010-first-blood/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 00:11:34 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[NuGet]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/03/02/installing-nuget-on-vs2010-first-blood/</guid>
		<description><![CDATA[So, here are the steps necessary to install NuGet on my windows laptop computer.&#160; I’ve got vs2010 (not sp1) installed, I’ve disabled both Resharper and .net Reflector just to be safe.  First step, is to go to the NuGet.org web site and click on Install.    &#160;  Accept the default:  [...]]]></description>
			<content:encoded><![CDATA[<p>So, here are the steps necessary to install <a href="http://nuget.codeplex.com/">NuGet</a> on my windows laptop computer.&#160; I’ve got vs2010 (not sp1) installed, I’ve disabled both Resharper and .net Reflector just to be safe.</p>  <p>First step, is to go to the <a href="http://nuget.org/">NuGet.org</a> web site and click on Install.</p>  <p><a href="http://nuget.org/"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image.png" width="449" height="234" /></a></p>  <p>&#160;</p>  <p>Accept the default:</p>  <p>&#160;</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb.png" width="244" height="182" /></a></p>  <p>&#160;</p>  <p>Run Visual Studio 2010 again, then go into Tool/Extension Manager and select “Automatically check for updates to installed extensions” as follows:</p>  <p>&#160;</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_3.png" width="515" height="398" /></a></p>  <p>&#160;</p>  <p>Then, go to View / Other Windows / Package Manager and you will get the Nu-Get prompt.</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_4.png" width="466" height="401" /></a></p>  <p>&#160;</p>  <p>Now, you&#8217; have the NuGet prompt as follows.</p>  <p>&#160;</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_5.png" width="420" height="181" /></a></p>    <p>At the PM prompt, to install scaffolding, start typing the following:</p>  <p>Install-Package mvc&#160; {then press tab for auto expansion}</p>  <p>You’ll get a list of all packages that begin with mvc as follows:</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_6.png" width="498" height="323" /></a></p>    <p>I choose MvcScaffolding, press enter and.. you’ll get the error that you need to have a project open.&#160; Of course, because it wants to add it to your project.</p>  <p>&#160;</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_7.png" width="368" height="379" /></a></p>  <p>&#160;</p>  <p>Now, let me add a real project with a simple class called MyTeam</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MyTeam<br />    {<br />        <br />        [Key]<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> ID { get; set; }<br /><br />        [Required]<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name { get; set; }<br />        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> City { get; set; }<br />        <span style="color: #0000ff">public</span> DateTime Founded { get; set; }<br />    }</pre>

  <br /></div>



<p>Now, when I re-run the last command, I get all my Controllers and Views.</p>

<p><a href="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/Installing-NuGet-on-VS2010-first-blood_D77F/image_thumb_8.png" width="610" height="251" /></a></p>



<p>Hope this helps, I have a lot more to learn now.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/03/02/installing-nuget-on-vs2010-first-blood/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Returning JsonResult From ASP.NET MVC 2.0 Controller and Unit Testing</title>
		<link>http://peterkellner.net/2010/05/14/unit-test-jsonresult-aspnet-mvc-reflection/</link>
		<comments>http://peterkellner.net/2010/05/14/unit-test-jsonresult-aspnet-mvc-reflection/#comments</comments>
		<pubDate>Sat, 15 May 2010 04:19:31 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/05/14/unit-test-jsonresult-aspnet-mvc-reflection/</guid>
		<description><![CDATA[   * I’m adding this comment after the post has been written to let anyone coming here know of another great post that goes further to explain no only what I’ve done here, but also two other ways including Mock and using Json Serialization.&#160; The Post is written by Ashic Mahtab, aka “HeartattacK” [...]]]></description>
			<content:encoded><![CDATA[<blockquote>   <p>* I’m adding this comment after the post has been written to let anyone coming here know of another great post that goes further to explain no only what I’ve done here, but also two other ways including Mock and using Json Serialization.&#160; The Post is written by <a href="http://www.heartysoft.com/page/about.aspx">Ashic Mahtab</a>, aka “<a href="http://forums.asp.net/members/HeartattacK.aspx">HeartattacK</a>” on the forums.&#160; His well written and informative article is here:&#160; <a href="http://www.heartysoft.com/post/2010/05/25/ASPNET-MVC-Unit-Testing-JsonResult-Returning-Anonymous-Types.aspx">ASP.NET MVC – Unit Testing JsonResult Returning Anonymous Types</a>.</p> </blockquote>  <p>This post will show how to return a simple Json result from an <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c9ba1fe1-3ba8-439a-9e21-def90a8615a9&amp;displaylang=en">ASP.NET MVC 2.0</a> web project.&#160; It will show how to test that result inside a unit test and essentially pick apart the Json, just like a JavaScript (or other client) would do.&#160; It seems like it should be very simple (and indeed, once you see the answer it is), however there are lots of length discussions on the forums about this with all kinds of positives and negatives.&#160; The one I based my solution on is from Stack Overflow and is <a href="http://stackoverflow.com/questions/482363/should-my-mvc-controller-really-know-about-json">here</a>..&#160; My personal length discussion that did not really yield a satisfactory answer is <a href="http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/552b6dda-5e98-4012-8df2-70a845aab680/">here</a>.</p>  <p>If you follow my method, you’ll be able to unit test a <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonresult.aspx">JsonResult</a> created by an <a href="http://www.asp.net/(S(d35rmemuuono1wvm1gsp2n45))/mvc">MVC asp.net web application</a>. </p> <span id="more-1316"></span>  <h2>Controller Side (Server)</h2>  <p>Let’s get started. First thing we need to do is have a controller that return a JsonResult.&#160; Below is the one I’m currently working on.&#160; Let me show the code, then explain it.</p>  <p>&#160;</p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> ActionResult Get(FormCollection form)<br />       {<br />           var query = <span style="color: #0000ff">new</span> FolderPairQuery();<br />           <span style="color: #0000ff">if</span> (form[<span style="color: #006080">&quot;query&quot;</span>] != <span style="color: #0000ff">null</span>)<br />           {<br />               query = form[<span style="color: #006080">&quot;query&quot;</span>].FromJson&lt;FolderPairQuery&gt;();<br />           }<br /><br />           <span style="color: #0000ff">if</span> (form[<span style="color: #006080">&quot;start&quot;</span>] != <span style="color: #0000ff">null</span> &amp;&amp; form[<span style="color: #006080">&quot;limit&quot;</span>] != <span style="color: #0000ff">null</span>)<br />           {<br />               query.Start = Convert.ToInt32(form[<span style="color: #006080">&quot;start&quot;</span>]);<br />               query.Limit = Convert.ToInt32(form[<span style="color: #006080">&quot;limit&quot;</span>]);<br />           }<br /><br />           var results = FolderPairManager.I.Get(query);<br />           <span style="color: #0000ff">return</span> Json(<span style="color: #0000ff">new</span><br />                           {<br />                               success = <span style="color: #0000ff">true</span>,<br />                               rows = results,<br />                               total = query.OutputTotal<br />                           }, JsonRequestBehavior.AllowGet);<br />       }</pre>
</div>

<div>&#160;</div>

<p>This code is actually part of the file FolderPairController.cs.&#160; It returns an ActionResult (which in this case is JsonResult that derives from ActionResult).&#160; All the way to the return statement is just stuff that I do in my code to pull apart the passed in Request variables and process them.&#160; I only leave them in for context.&#160; It does not matter how you get your “results” and “total”, it just matters that you do. Then, the return statement is the part that is of interest.&#160; It’s basically returning an anonymous class which is actually a JsonResult.&#160; In System.Web.Mvc.Controller.cs, you will see that Json is defined as:</p>

<p>&#160;</p>

<div>
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">internal</span> JsonResult Json(<span style="color: #0000ff">object</span> data, JsonRequestBehavior behavior);</pre>
</div>

<div>&#160;</div>

<div>&#160;</div>

<div>The first parameter is “object data” which means it can be anything, and in our case, it is an anonymous object.</div>

<div>&#160;</div>

<h2>Unit Test Side (Client)</h2>

<div>&#160;</div>

<div>So now, let’s take a look at the unit test itself.&#160; Again, let me show the code, then explain it.</div>

<div>&#160;</div>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> InsertControllerTest()<br />{<br />    var pairName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;FolderPair {0}&quot;</span>, <br />        (<span style="color: #0000ff">new</span> Random().Next(1, 10000)));<br />    var folderPairResults =<br />        <span style="color: #0000ff">new</span> List&lt;FolderPairResult&gt;()<br />            {<br />                <span style="color: #0000ff">new</span> FolderPairResult<br />                    {<br />                        ActionTypeId = 1,<br />                        CheckFileContent = <span style="color: #0000ff">true</span>,<br />                        ActiveForRunAll = <span style="color: #0000ff">true</span>,<br />                        ExcludeHiddenFiles = <span style="color: #0000ff">true</span>,<br />                        ExcludeReadOnly = <span style="color: #0000ff">true</span>,<br />                        ExcludeSystemFiles = <span style="color: #0000ff">true</span>,<br />                        FolderPairName = pairName,<br />                        LeftFolder = <span style="color: #006080">&quot;left&quot;</span>,<br />                        RightFolder = <span style="color: #006080">&quot;right&quot;</span>,<br />                        SaveOverWrittenRecycleBin = <span style="color: #0000ff">true</span>,<br />                        UsersId = 1<br />                    }<br />            };<br /><br /><br /><br />    <span style="color: #0000ff">string</span> jsonInsert = JsonConvert.SerializeObject(folderPairResults);<br /><br />    var form =<br />        <span style="color: #0000ff">new</span> FormCollection<br />            {<br />                {<span style="color: #006080">&quot;data&quot;</span>, jsonInsert}<br />            };<br /><br /><br />    <span style="color: #0000ff">using</span> (var controller = <span style="color: #0000ff">new</span> FolderPairController())<br />    {<br /><br />        controller.Insert(form);<br />    }<br /><br />    <span style="color: #008000">// verify it got inserted.</span><br />    var queryObj = <span style="color: #0000ff">new</span> FolderPairQuery { FolderPairName = pairName };<br />    <span style="color: #0000ff">string</span> json = JsonConvert.SerializeObject(queryObj);<br />    var formGet =<br />        <span style="color: #0000ff">new</span> FormCollection()<br />            {<br />                {<span style="color: #006080">&quot;query&quot;</span>, json}<br />            };<br /><br />    <span style="color: #0000ff">using</span> (var controller = <span style="color: #0000ff">new</span> FolderPairController())<br />    {<br />        var jsonResult1 = controller.Get(formGet) <span style="color: #0000ff">as</span> JsonResult;<br />        Assert.IsNotNull(jsonResult1,<span style="color: #006080">&quot;jsonResult1 is null which is bad&quot;</span>);<br />       <br />       <br />            List&lt;FolderPairResult&gt; folderPairResults1 =<br />                (List&lt;FolderPairResult&gt;)<br />                (jsonResult1.Data.GetType().GetProperty(<span style="color: #006080">&quot;rows&quot;</span>)).GetValue(jsonResult1.Data, <span style="color: #0000ff">null</span>);<br />            <span style="color: #0000ff">bool</span> success =<br />                (<span style="color: #0000ff">bool</span>)<br />                (jsonResult1.Data.GetType().GetProperty(<span style="color: #006080">&quot;success&quot;</span>)).GetValue(jsonResult1.Data, <span style="color: #0000ff">null</span>);<br />            <span style="color: #0000ff">int</span> total =<br />                (<span style="color: #0000ff">int</span>)<br />                (jsonResult1.Data.GetType().GetProperty(<span style="color: #006080">&quot;total&quot;</span>)).GetValue(jsonResult1.Data, <span style="color: #0000ff">null</span>);<br /><br />            Assert.IsTrue(folderPairResults1.Count == 1, <span style="color: #006080">&quot;Not one item returned&quot;</span>);<br />            Assert.IsTrue(folderPairResults1[0].FolderPairName.Equals(pairName),<br />                <span style="color: #006080">&quot;Wrong pairname returned&quot;</span>);<br />    }<br />}</pre>

  <br /></div>

<div>Up to the line “// verify it got inserted”, we simply are adding the record to the database in our unit test.&#160; I won’t go into detail about that in this post since it is not really the purpose here.&#160; I’m really just trying to show how to extract from the JsonResult the values that are returned from the server.</div>

<div>&#160;</div>

<div>So, notice the line “var jsonResult1 = controller.Get(formGet) as JsonResult;”.&#160; This line simply calls the controller’s get method with the appropriate query parameters and returns us a JsonResult.&#160; Now, let’s look at how to get the data out of that.&#160; It’s really quite simple using reflection.&#160; Each of the following three lines pulls the data out so that at the end, we have our typed data for rows,total and count.</div>

<div>&#160;</div>

<div>Hopefully, this will help you.&#160; Like I said in the beginning, there are lots of ways to do this.&#160; This just shows one that works for me.</div>

<div>&#160;</div>

<div>
  <br /></div>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/05/14/unit-test-jsonresult-aspnet-mvc-reflection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Is There A Need For End-To-End ExtJS to Microsoft Server (MVC-C#, LOB) 4 Day Class? (Poll Enclosed)</title>
		<link>http://peterkellner.net/2010/05/04/lob-training-poll-using-extjs-dotnet-aspnet-mvc/</link>
		<comments>http://peterkellner.net/2010/05/04/lob-training-poll-using-extjs-dotnet-aspnet-mvc/#comments</comments>
		<pubDate>Wed, 05 May 2010 02:54:13 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1289</guid>
		<description><![CDATA[Over the past couple years, the focus of the web development I’ve been doing involves building highly flexible, highly scalable and straight forward web sites to implement and maintain Line of Business (LOB) applications.&#160; As you can probably tell from my posts, I’m very “practical” focused, and at the same time have a desire to [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past couple years, the focus of the web development I’ve been doing involves building highly flexible, highly scalable and straight forward web sites to implement and maintain <a href="http://en.wikipedia.org/wiki/Line_of_business">Line of Business</a> (LOB) applications.&#160; As you can probably tell from my posts, I’m very “practical” focused, and at the same time have a desire to build awesome web applications.</p>  <p>The technology pairing I’ve chosen is <a href="http://www.asp.net/mvc/whatisaspmvc/">Microsoft’s .Net platform with MVC</a> on the server, and <a href="http://www.extjs.com/">ExtJS</a> on the client.&#160; Though it’s possible to still use ExtJS with standard html/aspx pages, I’ve found the best combination is to use 100% <a href="http://www.javascript.com/">JavaScript</a> on the client (ExtJS) and have all the server side technology be 100% service based.&#160; I’ve used <a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx">LINQ2SQL</a> extensively as well as <a href="http://msdn.microsoft.com/en-us/magazine/ee336128.aspx">Entity Framework</a> in the latest <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2010</a> release.</p>  <p>The learning curve was quite steep to actually be able to efficiently build highly flexible, highly scalable applications using these technologies, but now that I know it, I wouldn’t have it any other way.</p>  <p>I’m considering putting together a series of <strong>4 Day Classes</strong> around the country (or even world) that would basically teach people the methods and patterns I’ve learned and essentially leap frog a development team into being able to quickly do what it has taken me years to figure out.&#160; I’ve been fortunate enough to know the top 1% instructors and I’m sure with the right incentive, can get them to join me in both putting together these classes as well as teaching them.</p> <span id="more-1289"></span>  <p>So, my question is:</p> Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.   <p>I really appreciate your feedback.&#160; If I go down this path, it will be a lot of work and it would be nice to know if people are really interested.&#160; I know for myself, I&#8217; would have gone to something like this 2 years ago and it would have saved me a lot of time.</p>  <p>Thanks for your feedback.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/05/04/lob-training-poll-using-extjs-dotnet-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How To View JSON in a Pretty Way</title>
		<link>http://peterkellner.net/2009/11/06/formatting-json-best-tool/</link>
		<comments>http://peterkellner.net/2009/11/06/formatting-json-best-tool/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:49:04 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/11/06/formatting-json-best-tool/</guid>
		<description><![CDATA[Cutting to the chase, I choose Vladimir Bodurov’s Color Formatter!  For the past year or so, I’ve been working on a project that uses Microsoft’s ASP.NET MVC for providing data to our pure JavaScript application.&#160; That is, there are no web forms, no dynamic HTML generation, just 100% JavaScript running on the client.&#160; I’m [...]]]></description>
			<content:encoded><![CDATA[<p>Cutting to the chase, I choose <a href="http://blog.bodurov.com/Formatter-and-colorer-of-raw-JSON-code">Vladimir Bodurov’s Color Formatter!</a></p>  <p>For the past year or so, I’ve been working on a project that uses Microsoft’s <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> for providing data to our pure JavaScript application.&#160; That is, there are no web forms, no dynamic HTML generation, just 100% JavaScript running on the client.&#160; I’m using a library called <a href="http://extjs.com">ExtJS</a> which gives us high quality “forms like” user interactions and MVC for getting the data.&#160; That is, the Application looks like this:</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_thumb.png" width="231" height="283" /></a></p>  <p>The data retrieval URL used by the JavaScript look like:</p> <span id="more-378"></span>  <p><a href="http://www.mycompany.com/data/Company/Get">http://www.mycompany.com/data/Company/Get</a></p>  <p>And, the JSON that comes back using either FireBug or Fiddler looks like this:</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_thumb_3.png" width="244" height="170" /></a></p>  <p>Problem is that it’s hard to read the JSON data.&#160; <a href="http://getfirebug.com/">Firebug</a> does a reasonable job of formatting, but it’s still not perfect.&#160; Up until now, the way I always have formatted the data is to type into <a href="http://www.bing.com/search?q=format+json&amp;form=QBLH&amp;qs=n">bing</a> or <a href="http://www.google.com/search?hl=en&amp;source=hp&amp;q=json+format&amp;rlz=1R2GGLL_enUS341&amp;aq=f&amp;oq=&amp;aqi=g-p2g4g-s1g3">Google</a> “format json” and the first reasonable choice has been <a title="http://jsonformat.com/" href="http://jsonformat.com/">http://jsonformat.com/</a>.&#160; Cutting and pasting my data into it shows:</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_thumb_4.png" width="244" height="241" /></a></p>  <p>However, my new favorite JSON Formatter&#160; makes the data look like this:</p>  <p>( <a title="http://www.bodurov.com/JsonFormatter/" href="http://www.bodurov.com/JsonFormatter/">http://www.bodurov.com/JsonFormatter/</a> )</p>  <p>(more information at: <a title="http://blog.bodurov.com/Formatter-and-colorer-of-raw-JSON-code" href="http://blog.bodurov.com/Formatter-and-colorer-of-raw-JSON-code">http://blog.bodurov.com/Formatter-and-colorer-of-raw-JSON-code</a>)</p>  <p>And, it’s available as simple html you can run on your own server here at codeplex:</p>  <p><a title="http://www.codeplex.com/QuickJsonFormatter/Release/ProjectReleases.aspx?ReleaseId=10136" href="http://www.codeplex.com/QuickJsonFormatter/Release/ProjectReleases.aspx?ReleaseId=10136">http://www.codeplex.com/QuickJsonFormatter/Release/ProjectReleases.aspx?ReleaseId=10136</a></p>  <p>&#160;</p>  <p><a href="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/HowToViewJSONinaPrettyWay_741F/image_thumb_5.png" width="305" height="393" /></a></p>  <p>IMHO, much cleaner, shows me the data both before and after, as well as colorizes it which always makes me happy.</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/11/06/formatting-json-best-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>View a Generic List with ASP.NET MVC. Step by Step With Preview 5</title>
		<link>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/</link>
		<comments>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 18:35:28 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/</guid>
		<description><![CDATA[I&#8217;ve just started (within the past 2 days) learning and building a prototype with Microsoft&#8217;s new MVC platform.&#160; It&#8217;s really just another project type in Visual Studio 2008, but it changes the way you write asp.net applications.&#160; So far I like it, but I&#8217;m still on the honeymoon.&#160; I have not really tried to do [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just started (within the past 2 days) learning and building a prototype with <a href="http://forums.asp.net/">Microsoft&#8217;s new MVC platform</a>.&#160; It&#8217;s really just another project type in <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio 2008</a>, but it changes the way you write asp.net applications.&#160; So far I like it, but I&#8217;m still on the honeymoon.&#160; I have not really tried to do anything complex yet, and because it&#8217;s new to me, the simple things are still hard.&#160; <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">Scott Guthrie&#8217;s</a> posts posts have been helpful, as well as reading a pre-release of Manning&#8217;s upcoming book <a href="http://manning.com/palermo/">ASP.NET MVC In Action</a> by <a href="http://jeffreypalermo.com/">Jeffrey Palermo</a>, <a href="http://www.flux88.com/">Ben Scheirman</a> and <a href="http://grabbagoft.blogspot.com/">Jimmy Bogard</a>.</p> <span id="more-158"></span>  <p>So, as is normal, when I learn something new, the most obvious things just don&#8217;t seem to work.&#160; In this case, I&#8217;m just trying to make a web page that shows a list of data on a page.&#160; I&#8217;m not going to try and teach MVC here, but if you are like me and struggled with this, this should help you get through some of the tough spots. My plan is to start a new MVC project with Visual Studio and show you what is necessary to generate the list.&#160; Instead of going after a database, I&#8217;m going to use an simple business object class so you can run this without connecting to a database.&#160; Not sure about you, but I never seem to be able to get the databases from example code working.&#160; Scott Guthrie uses the Northwind databases Product table, and after spending about 15 minutes searching, all I could find was a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;displaylang=en">Northwind database from sqlserver 2000</a> that does not have a Product table.&#160; With my demo, you won&#8217;t have to worry about that.&#160; By the way, here is the project if you want to download it in action.</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:18d43e01-4549-4fde-8ca6-c7b4b7385fac:176475a3-eab9-41db-8107-c37ea0c2a70b" class="wlWriterSmartContent">   <p>Download Solution &#8211; <a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/Solution.zip">Solution.zip</a></p> </div>  <p>So, Here we go.&#160; First thing, Open Visual Studio 2008 and create a new MVC Project (not a web site, this will give you a csproj type file)</p>  <p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb.png" width="535" height="424" /></a></p>  <p>Answer the next question YES because of course you want a Test Project.</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_3.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_3.png" width="424" height="284" /></a></p>  <p>You should get a Solution that looks like this:</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_4.png" width="197" height="330" /></a></p>  <p>Now, Add the business object that I will be using for this rest of this demonstration.&#160; It&#8217;s in the project file, our you just download it here (put this in your Models Directory).</p>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:73729366-c7a7-43f3-a538-5ec829978430" class="wlWriterSmartContent">   <p>BusinessObjectClass.cs <a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/BusinessObjectClass.cs" target="_blank">BusinessObjectClass.cs</a></p> </div>  <p>Now, let&#8217;s create the MVC Controller.&#160; Highlight the Controller&#8217;s Folder and say Add Item (TMI if I show you that).&#160; Here is the dialog.&#160; Create the name of your controller with the syntax {Name}Controller.&#160; In my case, the name is EmailListControler.cs.</p>  <p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_5.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_5.png" width="424" height="293" /></a></p>  <p>Add the following code to your EmailListController.cs file to retrieve some data and return it as a View (which will be processed by the View Page coming up).</p>  <div class="csharpcode">   <pre class="alt"><span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Linq;</pre>

  <pre class="alt"><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre>&#160;</pre>

  <pre class="alt"><span class="kwrd">namespace</span> Solution.Controllers</pre>

  <pre>{</pre>

  <pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> EmailListController : Controller</pre>

  <pre>    {</pre>

  <pre class="alt">        <span class="kwrd">public</span> ActionResult Index()</pre>

  <pre>        {</pre>

  <pre class="alt">            var businessObject = <span class="kwrd">new</span> BusinessObject();</pre>

  <pre>            List&lt;BusinessObjectItem&gt; members = </pre>

  <pre class="alt">                businessObject.GetMembers();</pre>

  <pre>            <span class="kwrd">return</span> View(<span class="str">&quot;Index&quot;</span>, members);</pre>

  <pre class="alt">        }</pre>

  <pre>    }</pre>

  <pre class="alt">}<span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Linq;</pre>

  <pre class="alt"><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre>&#160;</pre>

  <pre class="alt"><span class="kwrd">namespace</span> Solution.Controllers</pre>

  <pre>{</pre>

  <pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> EmailListController : Controller</pre>

  <pre>    {</pre>

  <pre class="alt">        <span class="kwrd">public</span> ActionResult Index()</pre>

  <pre>        {</pre>

  <pre class="alt">            var businessObject = <span class="kwrd">new</span> BusinessObject();</pre>

  <pre>            List&lt;BusinessObjectItem&gt; members = </pre>

  <pre class="alt">                businessObject.GetMembers();</pre>

  <pre>            <span class="kwrd">return</span> View(<span class="str">&quot;Index&quot;</span>, members);</pre>

  <pre class="alt">        }</pre>

  <pre>    }</pre>

  <pre class="alt">}</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Then, create a new folder called EmailList under the Views folder.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_6.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_6.png" width="244" height="142" /></a></p>

<p>Then, create a MVCViewPage in the EmailList folder called Index.aspx.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_7.png"><img alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_7.png" width="612" height="360" /></a></p>

<p>(Actually, choose MVC View Content Page, not MVC View Page)</p>

<p>Then, chose the Master Page to use as follows (there is only one):</p>

<p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_8.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_8.png" width="579" height="354" /></a></p>

<p>The View will be referring to the ViewData.Model which somehow is associated with how the code behind is implemented. Make sure you have the ViewPage look like the following and the data type specified as below.&#160; This is the file Index.aspx.cs which is in your email directory.</p>

<div class="csharpcode">
  <pre class="alt"><span class="kwrd">using</span> System.Collections.Generic;</pre>

  <pre><span class="kwrd">using</span> System.Web.Mvc;</pre>

  <pre class="alt">&#160;</pre>

  <pre><span class="kwrd">namespace</span> Solution.Views.EmailList</pre>

  <pre class="alt">{</pre>

  <pre>    <span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Index :</pre>

  <pre class="alt">        ViewPage&lt;IEnumerable&lt;BusinessObjectItem&gt;&gt;</pre>

  <pre>    {</pre>

  <pre class="alt">    }</pre>

  <pre>}</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Now, for the Index.aspx file which is also in your Views/EmailList directory, enter the following between the content tags.</p>

<p>&#160;</p>

<div class="csharpcode">
  <pre class="alt">&lt;table border=<span class="str">&quot;1&quot;</span>&gt;</pre>

  <pre>    &lt;tr&gt;</pre>

  <pre class="alt">        &lt;td&gt;</pre>

  <pre>            &lt;strong&gt;Name&lt;/strong&gt;</pre>

  <pre class="alt">        &lt;/td&gt;</pre>

  <pre>        &lt;td&gt;</pre>

  <pre class="alt">            &lt;strong&gt;&lt;strong&gt;Email Address&lt;/strong&gt;</pre>

  <pre>        &lt;/td&gt;</pre>

  <pre class="alt">    &lt;/tr&gt;</pre>

  <pre>    &lt;% <span class="kwrd">foreach</span> (var emailItem <span class="kwrd">in</span> ViewData.Model)</pre>

  <pre class="alt">       { %&gt;</pre>

  <pre>    &lt;tr&gt;</pre>

  <pre class="alt">        &lt;td&gt;</pre>

  <pre>            &lt;%= emailItem.Name %&gt;</pre>

  <pre class="alt">        &lt;/td&gt;</pre>

  <pre>        &lt;td&gt;</pre>

  <pre class="alt">            &lt;%=emailItem.Email %&gt;</pre>

  <pre>        &lt;/td&gt;</pre>

  <pre class="alt">    &lt;/tr&gt;</pre>

  <pre>    &lt;% } %&gt;</pre>

  <pre class="alt">&lt;/table&gt;</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>Notice that you have intellisense working on your foreach items.</p>

<p>&#160;<a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_9.png"><img alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_9.png" width="554" height="141" /></a></p>

<p>Finally, go to your Master Page and add a link for this new EmailList as follows.&#160; That is, change the file /Views/Shared/Site.Master</p>

<div class="csharpcode">
  <pre class="alt">&lt;ul id=<span class="str">&quot;menu&quot;</span>&gt;              </pre>

  <pre>    &lt;li&gt;&lt;%= Html.ActionLink(<span class="str">&quot;Home&quot;</span>, <span class="str">&quot;Index&quot;</span>, <span class="str">&quot;Home&quot;</span>)%&gt;&lt;/li&gt;</pre>

  <pre class="alt">    &lt;li&gt;&lt;%= Html.ActionLink(<span class="str">&quot;About Us&quot;</span>, <span class="str">&quot;About&quot;</span>, <span class="str">&quot;Home&quot;</span>)%&gt;&lt;/li&gt;</pre>

  <pre>    &lt;li&gt;&lt;a href=<span class="str">&quot;/EmailList&quot;</span>&gt;Email List&lt;/a&gt;&lt;/li&gt;</pre>

  <pre class="alt">&lt;/ul&gt;</pre>
</div>
<style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>

<p>As you can see, I don&#8217;t quite grock the ActionLinke parameters so I just put in a standard anchor tag.&#160; Please comment below on what it should be to be able to reference /EmailList and I will update the article.&#160; For now, lunch is coming and I need to run.</p>

<p>When you finally run that app, you get this for your new output.&#160; Notice the New Email List Tab.</p>

<p><a href="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="/FilesForWebDownload/ViewaLINQListwith.StepbyStepWithPreview5_7BE7/image_thumb_10.png" width="625" height="382" /></a></p>

<p>That&#8217;s it for now.&#160; Hope this helps!</p>]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2008/09/09/mvc-tutorial-simple-generic-list-preview5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)
Database Caching 2/12 queries in 0.003 seconds using disk

Served from: peterkellner.net @ 2012-02-10 04:32:09 -->
