<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>.NET 3.5</title>
        <link>http://geekswithblogs.net/michelotti/category/7438.aspx</link>
        <description>.NET 3.5</description>
        <language>en-US</language>
        <copyright>Steve Michelotti</copyright>
        <managingEditor>steve.michelotti@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>ASP.NET MVC Application &amp;ndash; AlbumCredits.com</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/11/18/asp.net-mvc-application-ndash-albumcredits.com.aspx</link>
            <description>&lt;p&gt;Recently &lt;a href="http://appliedis.com/" target="_blank"&gt;my company&lt;/a&gt; just released the first version of a new MVC web site: &lt;a href="http://albumcredits.com/" target="_blank"&gt;AlbumCredits.com&lt;/a&gt;.  This project, led by &lt;a href="http://mo.notono.us/" target="_blank"&gt;Oskar Austegard&lt;/a&gt;, is was I consider a highly successful real-world implementation of MVC. In a time when most music these days is downloaded, the production and performance engineers, and recording professionals that work on the music don’t always get credit because there is no CD booklet to look through.  Album Credits is almost like a LinkedIn for recording professionals.  From the &lt;a href="http://albumcredits.com/about" target="_blank"&gt;about page&lt;/a&gt;:  AlbumCredits.com is “A fast, easy way to find production and performance credits from more than one million CDs and LPs.”&lt;/p&gt;  &lt;p&gt;We leveraged a ton of great technologies during the development of this solution. To name a few:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Custom Controller factory based on &lt;a href="http://structuremap.sourceforge.net/Default.htm" target="_blank"&gt;StructureMap&lt;/a&gt; Inversion of Control (IoC) container&lt;/li&gt;    &lt;li&gt;jQuery for all AJAX needs&lt;/li&gt;    &lt;li&gt;&lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471" target="_blank"&gt;T4MVC Templates&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Data Annotations for Validation&lt;/li&gt;    &lt;li&gt;&lt;a href="http://xval.codeplex.com/" target="_blank"&gt;xVal&lt;/a&gt; for client side validation&lt;/li&gt;    &lt;li&gt;LINQ to SQL with stored procedures (including a few UDFs) for data access&lt;/li&gt;    &lt;li&gt;SQL Server 2008 with Full Text Search&lt;/li&gt;    &lt;li&gt;SQL Server Integration Services for the data feed&lt;/li&gt;    &lt;li&gt;MvcFutures (functionality that will be baked in to MVC2)&lt;/li&gt;    &lt;li&gt;Numerous custom HTML Helpers&lt;/li&gt;    &lt;li&gt;Numerous third party jQuery plug ins including:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;jQuery UI&lt;/li&gt;      &lt;li&gt;jQuery Tools:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Tabs&lt;/li&gt;        &lt;li&gt;Scrollable&lt;/li&gt;        &lt;li&gt;Overlay&lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;Tablesorter&lt;/li&gt;      &lt;li&gt;jQuery Form&lt;/li&gt;      &lt;li&gt;Jcrop&lt;/li&gt;      &lt;li&gt;jWysiwyg&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;For unit testing – NUnit and NUnitEx&lt;/li&gt;    &lt;li&gt;For mocking - &lt;a href="http://code.google.com/p/moq/" target="_blank"&gt;Moq&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Additionally, on the build server we used:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Cruise Control .NET&lt;/li&gt;    &lt;li&gt;MSBuild&lt;/li&gt;    &lt;li&gt;FxCop&lt;/li&gt;    &lt;li&gt;StyleCop&lt;/li&gt;    &lt;li&gt;NUnit&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Album Credit starts with a nice AJAX auto-complete search box:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_ac-searchbox.GIF" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;The site is then “deep linkable”. Want to see what engineers worked on a particular album?  What other albums did they work on? Which other artists?  You can literally relate any category together in your searching - think &lt;a href="http://en.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon" target="_blank"&gt;Six Degrees of Kevin Bacon&lt;/a&gt; but for the music industry.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_ac-profile.GIF" width="750" height="619" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;It’s an example of a site that takes a very cool idea and melds it will a solid technical implementation.  &lt;a href="http://albumcredits.com/" target="_blank"&gt;Check it out&lt;/a&gt;!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136389"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136389" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/136389.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/11/18/asp.net-mvc-application-ndash-albumcredits.com.aspx</guid>
            <pubDate>Wed, 18 Nov 2009 15:15:35 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/136389.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/11/18/asp.net-mvc-application-ndash-albumcredits.com.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/136389.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/136389.aspx</trackback:ping>
        </item>
        <item>
            <title>LINQ to SQL Again??</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/11/10/linq-to-sql-again.aspx</link>
            <description>&lt;p&gt;Tomorrow night I’ll be at &lt;a href="http://www.rocknug.org/" target="_blank"&gt;RockNUG&lt;/a&gt; presenting LINQ to SQL. Yes, LINQ to SQL. Again. In the last 2 years I have presented LINQ to SQL numerous times at various user groups and code camps. Why do I keep getting asked to present LINQ to SQL? Isn’t LINQ to SQL dead? Answer: No.  LINQ to SQL is not dead!&lt;/p&gt;  &lt;p&gt;This confusion all started back in October 2008 with a seemingly &lt;a href="http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx" target="_blank"&gt;innocuous post&lt;/a&gt; on the ADO.NET team blog discussing the emphasis that Microsoft was going to put into the Entity Framework going forward.  The developer community was immediately up in arms about this post for a variety of reasons.  First, many developers and companies had already made a significant investment in developing with LINQ to SQL.  Secondly, LINQ to SQL is great so why de-emphasize it?  Third, the Entity Framework has had its share of challenges getting acceptance in the development community (and I’m being charitable) so the thought of replacing something “good” with something “not as good” was not met with enthusiasm.&lt;/p&gt;  &lt;p&gt;This led to a “&lt;a href="http://blogs.msdn.com/adonet/archive/2008/10/31/clarifying-the-message-on-l2s-futures.aspx" target="_blank"&gt;clarification message&lt;/a&gt;” by the ADO.NET team a few days later in which they clearly state: “LINQ to SQL is not dead.” This post may have been a somewhat weak defense of LINQ to SQL but the message was clear nonetheless. We’ve also seen others from Microsoft strongly advocate LINQ to SQL.  For example, in this &lt;a href="http://videos.visitmix.com/MIX09/T49F" target="_blank"&gt;MVC presentation at MIX 09&lt;/a&gt;, Scott Hanselman states he’s using LINQ to SQL in the demo “because it’s awesome and it’s not dead.” This all leads to a somewhat confusing state of affairs because we find ourselves relying on quotes from a respected Microsoft guru like Scott Hanselman and others in an attempt to translate Microsoft’s marketing approach for their latest data access strategy. After all, one of the longest running jokes is that the last thing Microsoft needs is yet another data access framework.&lt;/p&gt;  &lt;p&gt;So how do we make this pragmatic decision for ourselves when deciding on a data access strategy/framework? Although there are numerous data access choices, the top three frameworks that are typically examined are: 1) LINQ to SQL, 2) NHibernate, and 3) the Entity Framework (EF).&lt;/p&gt;  &lt;p&gt;The Entity Framework vNext that will be released after .NET 4.0 looks very promising.  &lt;a href="http://blogs.msdn.com/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx" target="_blank"&gt;Model first&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx" target="_blank"&gt;POCO code only&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/adonet/archive/2009/11/06/foreign-key-relationships-in-the-entity-framework.aspx" target="_blank"&gt;foreign key relationships&lt;/a&gt;, and more make me enthusiastic to give EF another run next year.  But…that’s next year. If you’re starting development on a new application today, you might think twice.&lt;/p&gt;  &lt;p&gt;NHibernate is a great framework. No dispute there. On it’s own it’s solid but then when you add features such as &lt;a href="http://fluentnhibernate.org/" target="_blank"&gt;Fluent NHibernate&lt;/a&gt; and &lt;a href="http://ayende.com/Blog/archive/2007/03/17/Implementing-Linq-for-NHibernate-A-How-To-Guide--Part.aspx" target="_blank"&gt;LINQ to NHibernate&lt;/a&gt; it’s becomes an extremely compelling choice. However, there is a steeper learning curve with NHibernate as compared to some other frameworks such as LINQ to SQL.  Additionally, some organizations (unfortunately) have policies against using open source software which disqualifies NHibernate in those environments.&lt;/p&gt;  &lt;p&gt;Then you’ve got trusty ol’ LINQ to SQL. In the last year, LINQ to SQL has continued to provide a solid data access choice. I strongly agree with the numerous points that Ian Cooper made in &lt;a href="http://codebetter.com/blogs/ian_cooper/archive/2008/07/02/showing-some-support-for-linq-to-sql.aspx" target="_blank"&gt;this post showing support for LINQ to SQL&lt;/a&gt;. In short, there are numerous reasons to learn and use LINQ to SQL. Among them:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;LINQ to SQL is a stable release and has withstood the test for 2 years now. You don’t have to wait for the next release (like EF) – you can use it *now*. &lt;/li&gt;    &lt;li&gt;Open source is not always an option (depending on your environment). LINQ to SQL is good to go here. &lt;/li&gt;    &lt;li&gt;The skills you learn in LINQ to SQL are transferrable.  In other words, if you learn LINQ to SQL now and later decide to switch to EF next year, you won’t be starting from scratch. Your knowledge will be transferrable. &lt;/li&gt;    &lt;li&gt;There are also some cool OSS projects for LINQ to SQL such as &lt;a href="http://www.codeplex.com/FluentLinqToSql" target="_blank"&gt;Fluent LINQ to SQL&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And finally, LINQ to SQL is just flat out *good*. While it may not be perfect (no framework is) the designers of LINQ to SQL inside Microsoft really got far more right than wrong when creating LINQ to SQL. You can use it with a RAD designer or you can hand code all your classes.  You can use it with C# attributes for mapping or external XML mapping files (or fluent mapping with OSS libraries). You can use it with auto-generated SQL or stored procedures. You can use it with POCO classes. You can use it in an N-Tier application without having to worry about serialization of your entities. It supports lazy loading or eager loading. The list goes on.&lt;/p&gt;  &lt;p&gt;Having implemented numerous production applications with LINQ to SQL, I’m happy with it. But I’ll continue to learn more about it and other data access technologies as well as they come out. &lt;/p&gt;  &lt;p&gt;If you’re in Rockville tomorrow night and have a desire to start learning LINQ to SQL, come on out!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136187"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=136187" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/136187.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/11/10/linq-to-sql-again.aspx</guid>
            <pubDate>Wed, 11 Nov 2009 02:26:39 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/136187.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/11/10/linq-to-sql-again.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/136187.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/136187.aspx</trackback:ping>
        </item>
        <item>
            <title>MVC AJAX Form with jQuery Form Plugin and jQuery Thickbox</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/09/01/mvc-ajax-form-with-jquery-form-plugin-and-jquery-thickbox.aspx</link>
            <description>&lt;p&gt;In a previous post, I showed how to submit an AJAX form in MVC with the &lt;a href="http://geekswithblogs.net/michelotti/archive/2009/08/31/mvc-ajax-form-with-ajax.beginform-and-jquery-thickbox.aspx" target="_blank"&gt;jQuery Thickbox and the built-in MVC AJAX helpers&lt;/a&gt;.  If you read that post first, it will show the complete context for how to simply submit an AJAX form that is being rendered inside a jQuery Thickbox with built-in MVC AJAX helpers.  But what if you want to stick to a pure jQuery solution?  That is also simple enough to do.  Instead of using the Ajax.BeginForm() method, you can use the &lt;a href="http://plugins.jquery.com/project/form" target="_blank"&gt;jQuery Form Plugin&lt;/a&gt;.  The code is almost identical to the previous implementation.  The only differences are in the Index.ascx partial view:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&amp;lt;MvcAjaxForm.Models.ContactMessage&amp;gt;" %&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    $(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        $(&lt;span class="str"&gt;"#contactForm"&lt;/span&gt;).ajaxForm({ target: &lt;span class="str"&gt;'#contactArea'&lt;/span&gt; });&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    });&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="contactForm"&lt;/span&gt; &lt;span class="attr"&gt;action&lt;/span&gt;&lt;span class="kwrd"&gt;="&amp;lt;%=Url.Action("&lt;/span&gt;&lt;span class="attr"&gt;Index&lt;/span&gt;&lt;span class="kwrd"&gt;", "&lt;/span&gt;&lt;span class="attr"&gt;Contact&lt;/span&gt;&lt;span class="kwrd"&gt;") %&amp;gt;"&lt;/span&gt; &lt;span class="attr"&gt;method&lt;/span&gt;&lt;span class="kwrd"&gt;="post"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="contactArea"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        Email Address: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.TextBox(&lt;span class="str"&gt;"EmailAddress"&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;        Message: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.TextArea(&lt;span class="str"&gt;"MessageText"&lt;/span&gt;)&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;On line 11, you will now specify a normal HTML form just like you might specify any other form in MVC (you could also use the Html.BeginForm() method as well if you have that preference). The only additional thing you have to implement is the one line of code shown on line 5 above.  This is making a call to the ajaxForm() method (that comes in the Form Plugin library) and passes in the options to indicate that the response from the server should be displayed in the “contactArea” div.  This is just one example of how to use the Form plugin – you can also find numerous example within the &lt;a href="http://malsup.com/jquery/form/#getting-started" target="_blank"&gt;Form Plugin’s documentation site&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134433"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134433" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/134433.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/09/01/mvc-ajax-form-with-jquery-form-plugin-and-jquery-thickbox.aspx</guid>
            <pubDate>Tue, 01 Sep 2009 11:28:11 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/134433.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/09/01/mvc-ajax-form-with-jquery-form-plugin-and-jquery-thickbox.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/134433.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/134433.aspx</trackback:ping>
        </item>
        <item>
            <title>MVC AJAX Form with Ajax.BeginForm() and jQuery Thickbox</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/31/mvc-ajax-form-with-ajax.beginform-and-jquery-thickbox.aspx</link>
            <description>&lt;p&gt;A relatively common scenario you might want in your application is the ability for a user to click a link that pops up a little dialog to submit some information.  For example, let’s say you have this form where the user could click the “Contact this person” link:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_mvc-ajax1.PNG" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;After clicking this link, it pops up the following dialog where the user can type in their message:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_mvc-ajax2.PNG" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Finally, once the user submits their message, it shows a little confirmation:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_mvc-ajax3.PNG" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;This scenario can be implemented with MVC with very few lines of code.  First off, we’ll be using the &lt;a href="http://www.dofactory.com/Ajax/AjaxMessageHtml.aspx" target="_blank"&gt;AJAX HTML Message pattern&lt;/a&gt; so that the AJAX messages that are going across the wire are simple HTML snippets.  Also, we’ll use jQuery &lt;a href="http://jquery.com/demo/thickbox/" target="_blank"&gt;Thickbox&lt;/a&gt; for our dialog. The first thing we need to do it to implement our “Contact this person” link:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.ActionLink(&lt;span class="str"&gt;"Contact this person"&lt;/span&gt;, &lt;span class="str"&gt;"Index"&lt;/span&gt;, &lt;span class="str"&gt;"Contact"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { height = 200, width = 300 }, &lt;span class="kwrd"&gt;new&lt;/span&gt; { @&lt;span class="kwrd"&gt;class&lt;/span&gt; = &lt;span class="str"&gt;"thickbox"&lt;/span&gt; }) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This is a pretty typical implementation of the jQuery thickbox.  We’re specifying that we want an AJAX call to be made to our ContactController.Index() method. The HTML that this ActionLink renders will simply look like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="thickbox"&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/Contact?height=200&amp;amp;amp;width=300"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Contact this person&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The complete code for the ContractController looks like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ContactController : Controller&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(&lt;span class="kwrd"&gt;new&lt;/span&gt; ContactMessage());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    [ActionName(&lt;span class="str"&gt;"Index"&lt;/span&gt;)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    [AcceptVerbs(HttpVerbs.Post)]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult SubmitMessage(ContactMessage message)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.View(&lt;span class="str"&gt;"Confirmation"&lt;/span&gt;, message);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;It is important to note that both views returned by the ContactController’s action methods are both partial views (i.e., Index.ascx and Confirmation.ascx) with our HTML snippets in there. We know that in the Index.ascx we want to do an AJAX form submission/post rather than a full page form submission. There are a couple of ways to do this including using the &lt;a href="http://plugins.jquery.com/project/form" target="_blank"&gt;jQuery Form plugin&lt;/a&gt;. However, in this case, the MVC framework already comes built-in with this functionality so we don’t have to rely on the jQuery Form plugin (unless we want to). Most of the time we find ourselves using the Html property of the View which is of type HtmlHelper.  However, there is also an Ajax property of the view of type &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.ajaxhelper.aspx" target="_blank"&gt;AjaxHelper&lt;/a&gt;. The AjaxHelper has a BeginForm method that will allow you to submit the form via AJAX. You’ll need to make sure you include the MicrosoftAjax.js and MicrosoftMvcAjax.js scripts in your page to use the Ajax helpers.  The complete implementation for the Index.ascx can just look like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&amp;lt;MvcAjaxForm.Models.ContactMessage&amp;gt;" %&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (Ajax.BeginForm(&lt;span class="str"&gt;"Index"&lt;/span&gt;, &lt;span class="str"&gt;"Contact"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxOptions { UpdateTargetId = &lt;span class="str"&gt;"contactArea"&lt;/span&gt; } )) { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="contactArea"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        Email Address: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.TextBox(&lt;span class="str"&gt;"EmailAddress"&lt;/span&gt;) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        Message: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.TextArea(&lt;span class="str"&gt;"MessageText"&lt;/span&gt;)&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; } &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Notice the UpdateTargetId is specifying the “contactArea” div.  This causes all HTML that is sent back on the form post (i.e., the confirmation message) to be displayed inside this div only.  The complete code for this sample can be downloaded &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=michelotti&amp;amp;DownloadId=7086" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134407"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134407" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/134407.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/31/mvc-ajax-form-with-ajax.beginform-and-jquery-thickbox.aspx</guid>
            <pubDate>Mon, 31 Aug 2009 09:00:18 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/134407.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/31/mvc-ajax-form-with-ajax.beginform-and-jquery-thickbox.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/134407.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/134407.aspx</trackback:ping>
        </item>
        <item>
            <title>FredNUG Code Samples</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/27/frednug-code-samples.aspx</link>
            <description>Thanks to everyone who attended my presentation last night at &lt;a href="http://frednug.org/"&gt;FredNUG&lt;/a&gt;.  The code samples can be downloaded &lt;a href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=michelotti&amp;amp;ReleaseId=938"&gt;here&lt;/a&gt;.&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134356"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134356" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/134356.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/27/frednug-code-samples.aspx</guid>
            <pubDate>Thu, 27 Aug 2009 16:30:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/134356.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/27/frednug-code-samples.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/134356.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/134356.aspx</trackback:ping>
        </item>
        <item>
            <title>C# 3.0 Deep Dish with a slice of C# 4.0 &amp;ndash; Code Samples</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/26/c-3.0-deep-dish-with-a-slice-of-c-4.0-again.aspx</link>
            <description>&lt;p&gt;Thanks to everyone who attended my presentation last night at &lt;a href="http://caparea.net/" target="_blank"&gt;CapArea&lt;/a&gt; on C# 3.0 and C# 4.0.  You can download the C# 3.0 code samples, C# 4.0 code samples, and the PowerPoint presentation from &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=michelotti&amp;amp;ReleaseId=3148" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Several people asked me about some of the tools I was using during the presentation.  A list of the tools that I use (and more) can be found &lt;a href="http://geekswithblogs.net/michelotti/archive/2008/11/23/developer-tools-and-utilities.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Feel free to email me with any questions.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134337"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134337" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/134337.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/26/c-3.0-deep-dish-with-a-slice-of-c-4.0-again.aspx</guid>
            <pubDate>Wed, 26 Aug 2009 14:04:51 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/134337.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/26/c-3.0-deep-dish-with-a-slice-of-c-4.0-again.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/134337.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/134337.aspx</trackback:ping>
        </item>
        <item>
            <title>Velocity CTP3 Set up for ASP.NET Session State</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/14/velocity-ctp3-set-up-for-asp.net-session-state.aspx</link>
            <description>&lt;p&gt;Historically I have always viewed ASP.NET session state as “pure evil.” In-proc session state is about as unreliable as you can get given that you can have timeouts, ASP.NET might recycle itself, IIS might get bounced, no scalability, and cannot work in a web farm.  SQL Session state is very resilient and works in web farm scenarios but the performance is not good and at that point you might as well be better off writing your own strongly-typed data access layer rather than blobbing everything in and out of the database.  ASP.NET state server is the “middle man” of the various options but it’s not very fault tolerant. As part of Microsoft’s &lt;a href="http://msdn.microsoft.com/en-us/data/cc655792.aspx" target="_blank"&gt;Velocity&lt;/a&gt; distributed cache they are providing an asp.net session state provider that is actually a *very* compelling option in my opinion for managing asp.net session state – more compelling than any of the traditional three choices.  It’s an in-memory distributed cache and it provides *both* high performance as well as robust fault tolerance potentially giving the best of both worlds.&lt;/p&gt;  &lt;p&gt;I recently set up Velocity CTP3 in my development environment and there were a couple of minor gotchas.  Many of the samples on the web were either incomplete or outdated (i.e., based on previous versions prior to CTP 3).  The links I found most helpful (in addition to the Velocity help file) to get everything set up were:  &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd861287.aspx" target="_blank"&gt;Build Better Data-Driven Apps With Distributed Caching&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/dd169031.aspx" target="_blank"&gt;How to: Configure a Session State Provider&lt;/a&gt;, and &lt;a href="http://andreacol.net/blog/velocity-ctp3-is-out/" target="_blank"&gt;Andrea Col’s Blog&lt;/a&gt;.  Putting all these links together, I was able to get it working.  This post will walk through all of the set up steps in a single place.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Step 1 – Download and run installer&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Download Velocity CTP 3 from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=B24C3708-EEFF-4055-A867-19B5851E7CD2&amp;amp;displaylang=en" target="_blank"&gt;this location&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Step 2 – Accept firewall defaults&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Step 3 – Cache Host Configuration&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;Create a new database called “Velocity” in SQL Server Management Studio. On the Cache Host Configuration screen, specify these values:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Storage Location type: SQL Server database &lt;/li&gt;    &lt;li&gt;Connection string: data source=&amp;lt;YourDBServer&amp;gt;;Initial Catalog=Velocity;Integrated Security=SSPI &lt;/li&gt;    &lt;li&gt;Cluster Name: “DevCluster” (this could really be anything) &lt;/li&gt;    &lt;li&gt;Cluster Size:  Small (1-4) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Leave all other defaults.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_CacheHostConfig.png" /&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 4 – Configure with PowerShell&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Start PowerShell Administration Tool found in the “Microsoft Distributed Cache” fold in Program Files off the Start menu.  The first time you run it can you choose “A” for always run software from this untrusted publisher.    &lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Execute&lt;/u&gt;:  Start-CacheCluster     &lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Execute&lt;/u&gt;:  New-Cache -CacheName ASPNETSessionCache -TTL 60     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;For verification you can look at the statistics for the cache you just created:&lt;/p&gt; &lt;u&gt;&lt;/u&gt;  &lt;p&gt;&lt;u&gt;Execute&lt;/u&gt;:  Get-CacheStatistics -CacheName ASPNETSessionCache&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 5 – Configure web.config&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The best reference I found for the web.config for CTP3 is &lt;a href="http://andreacol.net/blog/velocity-ctp3-is-out/" target="_blank"&gt;here&lt;/a&gt;.  You can copy/paste that and either leave as is or tweak if desired.  For example, you might want to change config values in the sessionState section for cookieless, etc. depending on your scenario.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Hope this helps ease the set up process.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134101"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134101" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/134101.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/14/velocity-ctp3-set-up-for-asp.net-session-state.aspx</guid>
            <pubDate>Fri, 14 Aug 2009 07:46:02 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/134101.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/14/velocity-ctp3-set-up-for-asp.net-session-state.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/134101.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/134101.aspx</trackback:ping>
        </item>
        <item>
            <title>MVC RadioButtonList HTML Helper &amp;ndash; Take 3</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/07/mvc-radiobuttonlist-html-helper-ndash-take-3.aspx</link>
            <description>&lt;p&gt;In two previous posts, I talked about ways to create your own HTML Helper to generate a radio button list.  In the &lt;a href="http://geekswithblogs.net/michelotti/archive/2009/08/05/mvc-radiobuttonlist-html-helper.aspx" target="_blank"&gt;first post&lt;/a&gt; I leveraged the &lt;a href="http://mvccontrib.codeplex.com/Wiki/View.aspx?title=FluentHtml" target="_blank"&gt;FluentHtml&lt;/a&gt; library to create a table layout.  In the &lt;a href="http://geekswithblogs.net/michelotti/archive/2009/08/06/mvc-radiobuttonlist-html-helper-ndash-take-2.aspx" target="_blank"&gt;second post&lt;/a&gt; I switched this to using a div instead of a table.  The crux of the issue was that I wanted to make sure the the “id” and “name” attributes were set correctly and MVC out of the box doesn’t seem to do this properly.  Recently I discovered a way to successfully do this without “wrapping” the FluentHtml library but by using it directly while leveraging a “RadioSet” like this:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=&lt;span class="kwrd"&gt;this&lt;/span&gt;.RadioSet(m =&amp;gt; m.Name).Options(Model.FooBarList) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;To produce HTML that looks like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Foo"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Foo"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Foo"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Foo_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Foo&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Bar"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Bar"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Bar"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Bar_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Bar&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;which is exactly what I want.  However, there are a couple of gotchas I ran into for making this work properly.  First off, it’s important to note that the Options() method above is taking an IEnumerable&amp;lt;SelectListItem&amp;gt; and FooBarList is IEnumerable&amp;lt;SelectListItem&amp;gt;.  The first thing I tried was creating my list like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;SelectListItem&amp;gt; CreateFooBarList()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; { &lt;span class="str"&gt;"Foo"&lt;/span&gt;, &lt;span class="str"&gt;"Bar"&lt;/span&gt; };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectList(list);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This resulted in HTML that was broken as the id’s and value’s were not set correctly:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Foo&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Bar&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So realized it was probably because that SelectListItem constructor just didn’t assign the Value property when a list of strings was sent in.  So I changed to this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;SelectListItem&amp;gt; CreateFooBarList()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;SelectListItem&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectListItem { Text = &lt;span class="str"&gt;"Foo"&lt;/span&gt;, Value = &lt;span class="str"&gt;"Foo"&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectListItem { Text = &lt;span class="str"&gt;"Bar"&lt;/span&gt;, Value = &lt;span class="str"&gt;"Bar"&lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectList(list);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I figured now that I was using an actual strongly-typed SelectList I would be all set.  But unfortunately, the rendered HTML was even worse now:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;System.Web.Mvc.SelectListItem&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="radio"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;for&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Name_Label"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;System.Web.Mvc.SelectListItem&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;It turns out that the way I had to fix this was to specify *all* arguments on the SelectList constructor with the dataTextField and dataValueField as shown on line #8 below:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;SelectListItem&amp;gt; CreateFooBarList()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;SelectListItem&amp;gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectListItem { Text = &lt;span class="str"&gt;"Foo"&lt;/span&gt;, Value = &lt;span class="str"&gt;"Foo"&lt;/span&gt; },&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectListItem { Text = &lt;span class="str"&gt;"Bar"&lt;/span&gt;, Value = &lt;span class="str"&gt;"Bar"&lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; SelectList(list, &lt;span class="str"&gt;"Value"&lt;/span&gt;, &lt;span class="str"&gt;"Text"&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Now the HTML and all attributes are correct.  You would *think* that the constructor of the SelectList would be smart enough to identify that the IEnumerable collection that was sent in was of type IEnumerable&amp;lt;SelectListItem&amp;gt; (which is what it ultimately wants) and set those arguments for you automatically. But it looks like that was a naive assumption on my part.  Easy enough to add a simple extension method to do this for you throughout your codebase. Make sure to watch out for this in your own code – I won’t make this mistake again.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133962"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133962" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/133962.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/07/mvc-radiobuttonlist-html-helper-ndash-take-3.aspx</guid>
            <pubDate>Fri, 07 Aug 2009 07:33:09 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/133962.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/07/mvc-radiobuttonlist-html-helper-ndash-take-3.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/133962.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/133962.aspx</trackback:ping>
        </item>
        <item>
            <title>Alternate MVC Screen Navigation</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/07/alternate-mvc-screen-navigation.aspx</link>
            <description>&lt;p&gt;Suppose you have a simple sequential screen flow in your application like this:&lt;/p&gt;  &lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/michelotti/4145/o_ScreenFlow.png" width="1279" height="203" /&gt; &lt;/p&gt;  &lt;p&gt;One typical scenario for this is that each screen has its own associated Controller (for the example we’ll say Controller1, Controller2, etc. but obviously they would have meaningful names in the real world).  When the user submits Screen1 then the code Controller 1 will have something like this:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.RedirectToAction(&lt;span class="str"&gt;"Index"&lt;/span&gt;, &lt;span class="str"&gt;"Controller2"&lt;/span&gt;);&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;In fact, each controller would have to have code like this that essentially “points to” the next controller in the sequential screen navigation. But if Screen 2 and Screen 4 swapped positions in the order, you’d have to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Change the code in Screen 1 to point to Screen 4 instead of 2 &lt;/li&gt;

  &lt;li&gt;Change the code in Screen 4 to point to Screen 3 instead of 5 &lt;/li&gt;

  &lt;li&gt;Change the code in Screen 2 to point to Screen 5 instead of 3 &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So in a case like this, it might make more sense to encapsulate this sequential order in a single place.  The goal would be to be able to change the code in each controller to something like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.RedirectToNextAction();&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;It’s actually not very much work to implement something like this.  First, you’d want to encapsulate everything in some type of “PageManager” class that has a GetNextStepFrom() method where you give it a controller name and it gives you back the next controller.  I’ve oversimplified an example in the interests of keeping this example simple:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; PageManager&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetNextStepFrom(&lt;span class="kwrd"&gt;string&lt;/span&gt; controller)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;int&lt;/span&gt; index = controllerList.IndexOf(controller);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; controllerList[index + 1];&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; controllerList = InitializeControllerSequence();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; InitializeControllerSequence()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            &lt;span class="str"&gt;"Controller1"&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;            &lt;span class="str"&gt;"Controller2"&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="str"&gt;"Controller3"&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;            &lt;span class="str"&gt;"Controller4"&lt;/span&gt;,&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  18:  &lt;/span&gt;            &lt;span class="str"&gt;"Controller5"&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  19:  &lt;/span&gt;        };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  20:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;  21:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;At this point, we’re ready to implement our RedirectToNextAction() method which is what makes all this work. The best way is to sub-class all your controllers and put this protected method in the base class:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; ActionResult RedirectToNextAction()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    var controllerName = &lt;span class="kwrd"&gt;this&lt;/span&gt;.RouteData.Values[&lt;span class="str"&gt;"Controller"&lt;/span&gt;].ToString();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    var nextController = PageManager.GetNextStepFrom(controllerName);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.RedirectToAction(&lt;span class="str"&gt;"Index"&lt;/span&gt;, nextController);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Notice that to get the name of the current controller, I’m having to get it from the RouteData dictionary.  What would be really nice if I could just do this.Name to get the name of the controller.  If you use the MVC T4 templates, it does give each controller class a Name property (although right now it’s actually a public field) but it’s not usable for this implementation in its current format because the Name property is not on the base class so can’t be used polymorphically.  Note that in C# 4.0, you could rewrite line #3 above to be:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;dynamic thisController = &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;var controllerName = thisController.Name;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This would be leveraging a form of &lt;a href="http://en.wikipedia.org/wiki/Duck_typing" target="_blank"&gt;duck typing&lt;/a&gt; but may be overkill for a scenario like this since you’re essentially relying on Reflection at this point.&lt;/p&gt;

&lt;p&gt;In any case, scenarios like these are good candidates for encapsulating the concern of screen navigation flow to an independent component outside the controllers.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133961"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133961" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/133961.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/07/alternate-mvc-screen-navigation.aspx</guid>
            <pubDate>Fri, 07 Aug 2009 06:08:14 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/133961.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/07/alternate-mvc-screen-navigation.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/133961.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/133961.aspx</trackback:ping>
        </item>
        <item>
            <title>Interesting LINQ Exercise</title>
            <link>http://geekswithblogs.net/michelotti/archive/2009/08/06/interesting-linq-exercise.aspx</link>
            <description>&lt;p&gt;A co-worker posed an interesting LINQ problem to me tonight so I figured I’d share.  They had a collection of items and wanted an algorithm that would create a “collection of collections” where the first three items would be grouped together, second three items, on so on.  For example, given a sequence like this: { “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h” }, it would create a structure that contained 3 groups – the first element would be { “a”, “b”, “c” }, the second would be { “d”, “e”, “f” } and the third { “g”, “h” }. They already had an algorithm working fine but it was using a “brute force” approach and took about 15-20 lines of code.  It “felt like” you could solve the same problem more elegantly with a LINQ solution and with less lines of code.&lt;/p&gt;  &lt;p&gt;Here was my first solution:&lt;/p&gt; &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; { &lt;span class="str"&gt;"a"&lt;/span&gt;, &lt;span class="str"&gt;"b"&lt;/span&gt;, &lt;span class="str"&gt;"c"&lt;/span&gt;, &lt;span class="str"&gt;"d"&lt;/span&gt;, &lt;span class="str"&gt;"e"&lt;/span&gt;, &lt;span class="str"&gt;"f"&lt;/span&gt;, &lt;span class="str"&gt;"g"&lt;/span&gt;, &lt;span class="str"&gt;"h"&lt;/span&gt; };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;var results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; numBlocks = list.Count % 3 == 0 ? list.Count / 3 : (list.Count / 3) + 1;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; numBlocks; i++)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    results.Add(list.Skip(i * 3).Take(3));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;First, I have to figure out the number of “blocks” or elements that the structure (the collection of collection) should have.  Next, for each “block position” I leverage the LINQ &lt;a href="http://msdn.microsoft.com/en-us/library/bb357513.aspx" target="_blank"&gt;Skip&lt;/a&gt; method in conjunction with the &lt;a href="http://msdn.microsoft.com/en-us/library/bb300906.aspx" target="_blank"&gt;Take&lt;/a&gt; method (essentially like a paging operation).  I was reasonably happy with the first solution but I kept feeling like I could do it with less lines of code and without the “for” loop.  The problem with eliminating the for loop is that it was providing the outer loop and with LINQ you basically have to loop over &lt;em&gt;something&lt;/em&gt;.  After a little digging, I came across the Enumerable &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx" target="_blank"&gt;Range&lt;/a&gt; method which I hadn’t used before.  This allowed me to solve the problem with 1 line of code:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; { &lt;span class="str"&gt;"a"&lt;/span&gt;, &lt;span class="str"&gt;"b"&lt;/span&gt;, &lt;span class="str"&gt;"c"&lt;/span&gt;, &lt;span class="str"&gt;"d"&lt;/span&gt;, &lt;span class="str"&gt;"e"&lt;/span&gt;, &lt;span class="str"&gt;"f"&lt;/span&gt;, &lt;span class="str"&gt;"g"&lt;/span&gt;, &lt;span class="str"&gt;"h"&lt;/span&gt; };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; numBlocks = list.Count % 3 == 0 ? list.Count / 3 : (list.Count / 3) + 1;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;var results = Enumerable.Range(0, numBlocks).Select(i =&amp;gt; list.Skip(i * 3).Take(3)).ToList();&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Now we’ve got our collection of collection and can iterate over it:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var item &lt;span class="kwrd"&gt;in&lt;/span&gt; results)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var innerItem &lt;span class="kwrd"&gt;in&lt;/span&gt; item)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        Console.WriteLine(innerItem);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;    }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;While I was originally happy that I found a way to do it with 1 line of code, it’s not really a great solution because it’s just a little “too clever”.  The for loop is going to be easier to understand for the poor developer that comes behind you and has to maintain your code.  Also, the second solution is not as efficient because the Range method creates an array just so i can loop over it just so it can make it workable in LINQ.  Bottom line, the first solution is better.  But of course, if someone has an even better solution, please do not hesitate to share it in the comment section below.&lt;/p&gt;

&lt;p&gt;To take it one step further, the LINQ &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany.aspx" target="_blank"&gt;SelectMany&lt;/a&gt; method will allow you to take the collection and collections and flatten it back out to the original single collection like this:&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;var flattened = results.SelectMany(x =&amp;gt; x);&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133953"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=133953" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/michelotti/aggbug/133953.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Steve Michelotti</dc:creator>
            <guid>http://geekswithblogs.net/michelotti/archive/2009/08/06/interesting-linq-exercise.aspx</guid>
            <pubDate>Thu, 06 Aug 2009 20:24:21 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/michelotti/comments/133953.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/michelotti/archive/2009/08/06/interesting-linq-exercise.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/michelotti/comments/commentRss/133953.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/michelotti/services/trackbacks/133953.aspx</trackback:ping>
        </item>
    </channel>
</rss>