<?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>Elegant Code &#187; MvcFutures</title>
	<atom:link href="http://elegantcode.com/tag/mvcfutures/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MvcFutures</title>
	<atom:link href="http://elegantcode.com/tag/mvcfutures/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Elegant Code &#187; MvcFutures</title>
	<atom:link href="http://elegantcode.com/tag/mvcfutures/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MvcFutures</title>
		<link>http://elegantcode.com/2010/03/13/mvcfutures/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mvcfutures</link>
		<comments>http://elegantcode.com/2010/03/13/mvcfutures/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 17:49:42 +0000</pubDate>
		<dc:creator>Tony Rasa</dc:creator>
				<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[ExpressionHelper]]></category>
		<category><![CDATA[MvcFutures]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/13/mvcfutures/</guid>
		<description><![CDATA[ASP.NET MVC 2 has been released (yay).&#160; One of the pieces I like about it is in the MvcFutures assembly.&#160; MvcFutures is where the MVC team puts code for features that may or may not make it into a future version of the MVC framework – undocumented, somewhat risky, but hey you get all the [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET MVC 2 has been released (yay).&#160; One of the pieces I like about it is in the MvcFutures assembly.&#160; MvcFutures is where the MVC team puts code for features that may or may not make it into a future version of the MVC framework – undocumented, somewhat risky, but hey you get all the source code if you find yourself painted into a corner.</p>  <p>One of the long-standing MVC practices has been ‘Shun Magic Strings.’&#160; For example, rather than specifying Controller/Action names in an ActionLink by string, we’ve always used an Expression&lt;Action&lt;TController&gt;&gt; instead to define the Controller class and Action method “in code.”&#160; If the action changes in the future, this gives you somewhat better abilities to discover the problem sooner vs. later.&#160; </p>  <p>MvcFutures includes a version of this idea, taken to the next level:&#160; you provide the expression with the arguments you want passed to the action included – you don’t provide a 2nd anonymous type defining the arguments.&#160; This gets rid of the somewhat confusing “null” arguments inside the expression, and just looks better overall.&#160; Plus, if the arguments to the action change, you’ll get better warning of that as well.</p>  <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" 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">&lt;asp:Content ID=<span style="color: #006080">&quot;Content2&quot;</span> ContentPlaceHolderID=<span style="color: #006080">&quot;MainContent&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span>&gt;<br />    &lt;h2&gt;Magic Strings are Evil&lt;/h2&gt;<br />    &lt;p&gt;<br />        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(16), <span style="color: #006080">&quot;A Number&quot;</span>) %&gt;<br />        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(32), <span style="color: #006080">&quot;Another Number&quot;</span>) %&gt;<br />        &lt;%= Html.ActionLink&lt;HomeController&gt;(c =&gt; c.FavoriteNumber(42), <span style="color: #006080">&quot;Yet Another Number&quot;</span>) %&gt;        <br />    &lt;/p&gt;<br />&lt;/asp:Content&gt;</pre>

  <br /></div>

<p>I like this method MUCH better.&#160; </p>

<p>The implementation that makes this happen is in Microsoft.Web.Mvc.Internal.ExpressionHelper.&#160; Which even though it’s in an “Internal” namespace, is neither marked Internal, Sealed, or otherwise made unavailable (hallelujah).&#160; So you can use this trick for all sorts of things.</p>

<p>There is also a System.Web.Mvc.ExpressionHelper in the official MVC assembly, which is used to implement the smart Html.TextBoxFor(m =&gt; m.Property) functionality.&#160; This class is also NOT internal, not sealed, not obfuscated and hidden away.&#160; We’ve used it to extend the Html.[control]For() abilities to some other control types.&#160; Very useful stuff.&#160; Plus its just interesting code to read.</p>

<p><strong>One potentially big caveat:</strong>&#160; I’m told that the Html.ActionLink&lt;TController&gt;() methods don’t work if you’re using Areas in your MVC application.&#160; I haven’t tried this myself, we aren’t using Areas in any of our MVC 2 applications yet.&#160; That might be why this functionality is hidden in MvcFutures and not out with the rest of the smart expression code.</p>]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/13/mvcfutures/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

