<?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>SquaredRoot &#187; session</title>
	<atom:link href="http://www.squaredroot.com/tag/session/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.squaredroot.com</link>
	<description>.Net Development in DC</description>
	<lastBuildDate>Sun, 16 Aug 2009 01:30:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Storing LINQ Objects in SQL-Based Session State</title>
		<link>http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/</link>
		<comments>http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 01:19:00 +0000</pubDate>
		<dc:creator>Troy Goode</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">/post/2008/01/30/Storing-LINQ-Objects-in-SQL-Based-Session-State.aspx</guid>
		<description><![CDATA[Scott Hanselman recently posted about various options you have for session storage while using ASP.Net. In the comments of his post I brough up an issue I recently encountered at work (where we use SQL Server session state): LINQ-To-Sql generated objects are not marked [Serializable] and cannot be stored in out-of-process session storage. To get [...]]]></description>
			<content:encoded><![CDATA[<p>
Scott Hanselman <a href="/post/2008/01/Storing-LINQ-Objects-in-SQL-Based-Session-State.aspx">recently posted about various options you have for session storage</a> while using ASP.Net. In the comments of his post I brough up an issue I recently encountered at work (where we use SQL Server session state):
</p>
<p>
<strong>LINQ-To-Sql generated objects are not marked [Serializable] and cannot be stored in out-of-process session storage.</strong>
</p>
<p>
To get around this I have whipped up the following helper class which will serialize LINQ-To-Sql objects if you set the DataContext&#39;s Serializable property to &quot;Unidirectional&quot;.
</p>
<p>
<strong>Note: The following class does not current work for storing List&lt;X&gt; where X is a LINQ-To-Sql object. I&#39;ll be working to resolve that sometime later this week.</strong>
</p>
<div class="csharpcode-wrapper">
<div class="csharpcode">
<pre class="alt">
<span class="lnum">   1:</span> <span class="kwrd">using</span> System;
</pre>
<pre class="alteven">
<span class="lnum">   2:</span> <span class="kwrd">using</span> System.IO;
</pre>
<pre class="alt">
<span class="lnum">   3:</span> <span class="kwrd">using</span> System.Runtime.Serialization;
</pre>
<pre class="alteven">
<span class="lnum">   4:</span> <span class="kwrd">using</span> System.Text;
</pre>
<pre class="alt">
<span class="lnum">   5:</span> <span class="kwrd">using</span> System.Xml;
</pre>
<pre class="alteven">
<span class="lnum">   6:</span> <span class="kwrd">using</span> System.Web;
</pre>
<pre class="alt">
<span class="lnum">   7:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">   8:</span> <span class="kwrd">namespace</span> SquaredRoot.Helper
</pre>
<pre class="alt">
<span class="lnum">   9:</span> {
</pre>
<pre class="alteven">
<span class="lnum">  10:</span>   <span class="kwrd">public</span> <span class="kwrd">class</span> SessionHelper
</pre>
<pre class="alt">
<span class="lnum">  11:</span>   {
</pre>
<pre class="alteven">
<span class="lnum">  12:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  13:</span>     <span class="kwrd">private</span> SessionHelper(){}
</pre>
<pre class="alteven">
<span class="lnum">  14:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  15:</span>         <span class="kwrd">public</span> <span class="kwrd">static</span> T Get&lt;T&gt;( <span class="kwrd">string</span> key ) <span class="kwrd">where</span> T : <span class="kwrd">class</span>
</pre>
<pre class="alteven">
<span class="lnum">  16:</span>         {
</pre>
<pre class="alt">
<span class="lnum">  17:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">  18:</span>             <span class="kwrd">object</span> o = HttpContext.Current.Session[key];
</pre>
<pre class="alt">
<span class="lnum">  19:</span>             <span class="kwrd">if</span>( o == <span class="kwrd">null</span> )
</pre>
<pre class="alteven">
<span class="lnum">  20:</span>                 <span class="kwrd">return</span> <span class="kwrd">default</span>( T );
</pre>
<pre class="alt">
<span class="lnum">  21:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">  22:</span>             <span class="kwrd">if</span>( o.GetType() == <span class="kwrd">typeof</span>( <span class="kwrd">string</span> ) &amp;&amp; <span class="kwrd">typeof</span>( T ) != <span class="kwrd">typeof</span>( <span class="kwrd">string</span> ) )
</pre>
<pre class="alt">
<span class="lnum">  23:</span>             {
</pre>
<pre class="alteven">
<span class="lnum">  24:</span>                 <span class="kwrd">string</span> s = o <span class="kwrd">as</span> <span class="kwrd">string</span>;
</pre>
<pre class="alt">
<span class="lnum">  25:</span>                 Stream stream = <span class="kwrd">new</span> MemoryStream( Encoding.Unicode.GetBytes(s) );
</pre>
<pre class="alteven">
<span class="lnum">  26:</span>                 XmlDictionaryReader xml = XmlDictionaryReader.CreateTextReader( stream, <span class="kwrd">new</span> XmlDictionaryReaderQuotas() );
</pre>
<pre class="alt">
<span class="lnum">  27:</span>                 DataContractSerializer dcs = <span class="kwrd">new</span> DataContractSerializer( <span class="kwrd">typeof</span>( T ) );
</pre>
<pre class="alteven">
<span class="lnum">  28:</span>                 T t = (T)dcs.ReadObject( xml, <span class="kwrd">true</span> );
</pre>
<pre class="alt">
<span class="lnum">  29:</span>                 xml.Close();
</pre>
<pre class="alteven">
<span class="lnum">  30:</span>                 <span class="kwrd">return</span> t;
</pre>
<pre class="alt">
<span class="lnum">  31:</span>             }
</pre>
<pre class="alteven">
<span class="lnum">  32:</span>             <span class="kwrd">else</span>
</pre>
<pre class="alt">
<span class="lnum">  33:</span>                 <span class="kwrd">return</span> o <span class="kwrd">as</span> T;
</pre>
<pre class="alteven">
<span class="lnum">  34:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  35:</span>         }
</pre>
<pre class="alteven">
<span class="lnum">  36:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  37:</span>         <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> HasClassAttribute( <span class="kwrd">object</span> o, Type attribute, <span class="kwrd">bool</span> inherit )
</pre>
<pre class="alteven">
<span class="lnum">  38:</span>         {
</pre>
<pre class="alt">
<span class="lnum">  39:</span>             <span class="kwrd">return</span> ( o.GetType().GetCustomAttributes( attribute, inherit ).Length &gt; 0 );
</pre>
<pre class="alteven">
<span class="lnum">  40:</span>         }
</pre>
<pre class="alt">
<span class="lnum">  41:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">  42:</span>         <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Set( <span class="kwrd">string</span> key, <span class="kwrd">object</span> item )
</pre>
<pre class="alt">
<span class="lnum">  43:</span>         {
</pre>
<pre class="alteven">
<span class="lnum">  44:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  45:</span>             <span class="kwrd">object</span> <span class="kwrd">value</span> = item;
</pre>
<pre class="alteven">
<span class="lnum">  46:</span>             <span class="kwrd">if</span>( HasClassAttribute( item, <span class="kwrd">typeof</span>(DataContractAttribute), <span class="kwrd">false</span> )
</pre>
<pre class="alt">
<span class="lnum">  47:</span>         &amp;&amp; !HasClassAttribute( item, <span class="kwrd">typeof</span>(SerializableAttribute), <span class="kwrd">false</span> ) )
</pre>
<pre class="alteven">
<span class="lnum">  48:</span>             {
</pre>
<pre class="alt">
<span class="lnum">  49:</span>                 DataContractSerializer dcs = <span class="kwrd">new</span> DataContractSerializer(item.GetType());
</pre>
<pre class="alteven">
<span class="lnum">  50:</span>                 StringBuilder sb = <span class="kwrd">new</span> StringBuilder();
</pre>
<pre class="alt">
<span class="lnum">  51:</span>                 XmlWriter writer = XmlWriter.Create(sb);
</pre>
<pre class="alteven">
<span class="lnum">  52:</span>                 dcs.WriteObject( writer, item );
</pre>
<pre class="alt">
<span class="lnum">  53:</span>                 writer.Close();
</pre>
<pre class="alteven">
<span class="lnum">  54:</span>                 <span class="kwrd">value</span> = sb.ToString();
</pre>
<pre class="alt">
<span class="lnum">  55:</span>             }
</pre>
<pre class="alteven">
<span class="lnum">  56:</span>&nbsp;
</pre>
<pre class="alt">
<span class="lnum">  57:</span>             <span class="kwrd">if</span>( HttpContext.Current.Session[key] == <span class="kwrd">null</span> )
</pre>
<pre class="alteven">
<span class="lnum">  58:</span>         HttpContext.Current.Session.Add( key, <span class="kwrd">value</span> );
</pre>
<pre class="alt">
<span class="lnum">  59:</span>             <span class="kwrd">else</span>
</pre>
<pre class="alteven">
<span class="lnum">  60:</span>         HttpContext.Current.Session[key] = <span class="kwrd">value</span>;
</pre>
<pre class="alt">
<span class="lnum">  61:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">  62:</span>         }
</pre>
<pre class="alt">
<span class="lnum">  63:</span>&nbsp;
</pre>
<pre class="alteven">
<span class="lnum">  64:</span>     }
</pre>
<pre class="alt">
<span class="lnum">  65:</span> }
</pre>
</div>
</div>
<div style="text-align: center;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/" style="border:0; position: relative; top: -2px;"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/" style="border:0;" alt="Kick It on DotNetKicks.com" /></a><a href="http://dotnetshoutout.com/Submit?url=http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/" style="border: 0;"><img src="http://dotnetshoutout.com/image.axd?url=http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/" style="border:0px" alt="Shout It on DotNetShoutOuts.com" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.squaredroot.com/2008/01/30/storing-linq-objects-in-sql-based-session-state/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MVC: ViewData vs. TempData</title>
		<link>http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/</link>
		<comments>http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 17:41:00 +0000</pubDate>
		<dc:creator>Troy Goode</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">/post/2007/12/20/MVC-ViewData-vs-TempData.aspx</guid>
		<description><![CDATA[NOTE: This article was written for the December CTP release of the MVC framework. Unfortunately, it does not entirely apply to the Preview 2 release or subsequent releases. A commenter (oVan) recently left a comment on one of my posts with a suggestion to redirect to a different URL rather than display a different view. [...]]]></description>
			<content:encoded><![CDATA[<blockquote class="warning"><p> 	<strong>NOTE</strong>:<br /> 	This article was written for the December CTP release of the MVC framework. Unfortunately, it does not entirely apply to the Preview 2 release or subsequent releases. 	</p>
</blockquote>
<p> A commenter (<a href="http://www.superwasp.net/weblog/">oVan</a>) recently <a href="/post/2007/12/ASPNet-MVC-Membership-Basics.aspx#Comment2fc1b651-b266-47e8-9b3a-c8e9700ae247">left a comment</a> on one of my posts with a suggestion to redirect to a different URL rather than display a different view. He cautioned that if I do so to make certain I use store data in the TempData dictionary rather than ViewData. I had not yet heard of the TempData dictionary, so I set off into <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> to find out what exactly it is.  </p>
<p> Initially it appeared that TempData was simply a Dictionary&lt;string,object&gt; stored in session. This is close to the truth, but not the whole truth. In fact the internal declaration of TempData&#39;s storage device is:  </p>
<p> <!--<br />
{rtf1ansiansicpglang1024noproof65001uc1 deff0{fonttbl{f0fnilfcharset0fprq1 Consolas;}}{colortbl;??red0green0blue0;red255green255blue255;red43green145blue175;red0green0blue255;}??fs18 Pair&lt;cf3 Dictionarycf0 &lt;cf4 stringcf0 , cf4 objectcf0 &gt;, cf3 HashSetcf0 &lt;cf4 stringcf0 &gt;&gt;}<br />
-->
<div style="background: white none repeat scroll 0% 0%; font-size: 9pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new">
<p style="margin: 0px; color: #2b91af"> Pair&lt;<span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">object</span>&gt;, <span style="color: #2b91af">HashSet</span>&lt;<span style="color: blue">string</span>&gt;&gt;  </p>
</p></div>
<p> &nbsp; </p>
<p> Why such a complicated declaration? Further digging revealed that the second element of the pair (the HashSet) is used as a kind of key synchronization device. When an item is added to the internal storage, the key is placed in the HashSet. At some point that I have been unable to determine, the key is removed from the HashSet. Then when the TempData object is built again, the discrepancy is noticed and the Dictionary entry that has a key not contained in the HashSet is removed from the Dictionary.  </p>
<p> The end result is that <strong>any data stored in TempData will be around for the life the current request and the next request only</strong>, or until the item is removed explicitly. This is useful when you want to pass data to another view that you will be redirecting to, rather than rendering to.  </p>
<p> <!--<br />
{rtf1ansiansicpglang1024noproof65001uc1 deff0{fonttbl{f0fnilfcharset0fprq1 Consolas;}}{colortbl;??red0green0blue0;red255green255blue255;red43green145blue175;red0green0blue255;red163green21blue21;red0green128blue0;red221green255blue221;}??fs18 [cf3 ControllerActioncf0 ]par ??cf4 publiccf0  cf4 voidcf0  Index()par ??{par ??tab TempData[cf5 "laugh"cf0 ] = cf5 "lol"cf0 ;par ??tab RedirectToAction( cf5 "Test1"cf0  );par ??tab cf6cb7highlight7 //RenderView("Index");par ??cf0cb0highlight0 }par ??par ??[cf3 ControllerActioncf0 ]par ??cf4 publiccf0  cf4 voidcf0  Test1()par ??{par ??tab cf4 stringcf0  laugh = TempData[cf5 "laugh"cf0 ] cf4 ascf0  cf4 stringcf0 ;par ??tab RenderView(cf5 "Test1"cf0 );par ??}par ??par ??[cf3 ControllerActioncf0 ]par ??cf4 publiccf0  cf4 voidcf0  Test2()par ??{par ??tab cf4 stringcf0  laugh = TempData[cf5 "laugh"cf0 ] cf4 ascf0  cf4 stringcf0 ;par ??tab RenderView(cf5 "Test2"cf0 );par ??}}<br />
-->
<div style="background: white none repeat scroll 0% 0%; font-size: 9pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new">
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 1</span> [<span style="color: #2b91af">ControllerAction</span>]  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 2</span>&nbsp;<span style="color: blue">public</span> <span style="color: blue">void</span> Index()  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 3</span> {  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 4</span>&nbsp;&nbsp;&nbsp;&nbsp; TempData[<span style="color: #a31515">&quot;text&quot;</span>] = <span style="color: #a31515">&quot;lorem ipsum&quot;</span>;  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 5</span>&nbsp;&nbsp;&nbsp;&nbsp; RedirectToAction( <span style="color: #a31515">&quot;Test1&quot;</span> );  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 6</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="background: #ddffdd none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: green">//RenderView(&quot;Index&quot;);</span>  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 7</span> }  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 8</span>&nbsp;  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp;&nbsp; 9</span> [<span style="color: #2b91af">ControllerAction</span>]  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 10</span>&nbsp;<span style="color: blue">public</span> <span style="color: blue">void</span> Test1()  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 11</span> {  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 12</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">string</span> text = TempData[<span style="color: #a31515">&quot;text&quot;</span>] <span style="color: blue">as</span> <span style="color: blue">string</span>;  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 13</span>&nbsp;&nbsp;&nbsp;&nbsp; RenderView(<span style="color: #a31515">&quot;Test1&quot;</span>);  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 14</span> }  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 15</span>&nbsp;  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 16</span> [<span style="color: #2b91af">ControllerAction</span>]  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 17</span>&nbsp;<span style="color: blue">public</span> <span style="color: blue">void</span> Test2()  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 18</span> {  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 19</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">string</span> text = TempData[<span style="color: #a31515">&quot;text&quot;</span>] <span style="color: blue">as</span> <span style="color: blue">string</span>;  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 20</span>&nbsp;&nbsp;&nbsp;&nbsp; RenderView(<span style="color: #a31515">&quot;Test2&quot;</span>);  </p>
<p style="margin: 0px"> <span style="color: #2b91af">&nbsp;&nbsp; 21</span> }  </p>
</p></div>
<p> &nbsp; </p>
<p> In the code above if you navigate to the Index page, you are automatically redirected to the Test1 action&#39;s URL. The Test1 action then executes and is able to access the data stored for it in TempData. If you then navigate to the Test2 action, that action is unable to retrieve the data previously stored in TempData.  </p>
<p> To retrieve data from TempData inside of a view, do the following:  </p>
<p> <!--<br />
{rtf1ansiansicpglang1024noproof65001uc1 deff0{fonttbl{f0fnilfcharset0fprq1 Consolas;}}{colortbl;??red0green0blue0;red255green238blue98;red255green255blue255;red0green0blue255;red163green21blue21;}??fs18 cb2highlight2 &lt;%cb0highlight0  cf4 =cf0 ViewContext.TempData[cf5 "text"cf0 ] cb2highlight2 %&gt;}<br />
-->
<div style="background: white none repeat scroll 0% 0%; font-size: 9pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new">
<p style="margin: 0px"> <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">&lt;%</span> <span style="color: blue">=</span>ViewContext.TempData[<span style="color: #a31515">&quot;text&quot;</span>] <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">%&gt;</span>  </p>
</p></div>
<p> &nbsp; </p>
<p> One suggestion for an improvement in the next CTP would be to have all data available in TempData copied over to ViewData at the beginning of a request (after the old TempData has been cleared). This would allow us to simply say:  </p>
<p> <!--<br />
{rtf1ansiansicpglang1024noproof65001uc1 deff0{fonttbl{f0fnilfcharset0fprq1 Consolas;}}{colortbl;??red0green0blue0;red255green238blue98;red255green255blue255;red0green0blue255;red163green21blue21;}??fs18 cb2highlight2 &lt;%cb0highlight0  cf4 =cf0 ViewData[cf5 "text"cf0 ] cb2highlight2 %&gt;}<br />
-->
<div style="background: white none repeat scroll 0% 0%; font-size: 9pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new">
<p style="margin: 0px"> <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">&lt;%</span> <span style="color: blue">=</span>ViewData[<span style="color: #a31515">&quot;text&quot;</span>] <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">%&gt;</span>  </p>
</p></div>
<p> &nbsp; </p>
<p> Otherwise the view has to be very aware of the controller and how it plans to pass data into the view. Currently I cannot have a view that supports being passed data both ways without doing the following:  </p>
<p> <!--<br />
{rtf1ansiansicpglang1024noproof65001uc1 deff0{fonttbl{f0fnilfcharset0fprq1 Consolas;}}{colortbl;??red0green0blue0;red255green238blue98;red255green255blue255;red0green0blue255;red163green21blue21;}??fs18 cb2highlight2 &lt;%cb0highlight0  cf4 =cf0 ViewContext.TempData[cf5 "text"cf0 ] ?? ViewData[cf5 "text"cf0 ] cb2highlight2 %&gt;}<br />
-->
<div style="background: white none repeat scroll 0% 0%; font-size: 9pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new">
<p style="margin: 0px"> <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">&lt;%</span> <span style="color: blue">=</span>ViewContext.TempData[<span style="color: #a31515">&quot;text&quot;</span>] ?? ViewData[<span style="color: #a31515">&quot;text&quot;</span>] <span style="background: #ffee62 none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">%&gt;</span>  </p>
</p></div>
<div style="text-align: center;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/" style="border:0; position: relative; top: -2px;"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/" style="border:0;" alt="Kick It on DotNetKicks.com" /></a><a href="http://dotnetshoutout.com/Submit?url=http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/" style="border: 0;"><img src="http://dotnetshoutout.com/image.axd?url=http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/" style="border:0px" alt="Shout It on DotNetShoutOuts.com" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.squaredroot.com/2007/12/20/mvc-viewdata-vs-tempdata/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
