<p>When a controller renders a view based on a model you can get the properties from the ViewData collection using the indexer (ie. ViewData["Property"]).  However, I have a shared user control that I tried to call using the following:</p>

<pre><code>return View("Message", new { DisplayMessage = "This is a test" });
</code></pre>

<p>and on my Message control I had this:</p>

<pre><code>&lt;%= ViewData["DisplayMessage"] %&gt;
</code></pre>

<p>I would think this would render the DisplayMessage correctly, however, null is being returned.  After a heavy dose of tinkering around, I finally created a "MessageData" class in order to strongly type my user control:</p>

<pre><code>public class MessageControl : ViewUserControl&lt;MessageData&gt;
</code></pre>

<p>and now this call works:</p>

<pre><code>return View("Message", new MessageData() { DisplayMessage = "This is a test" });
</code></pre>

<p>and can be displayed like this:</p>

<pre><code>&lt;%= ViewData.Model.DisplayMessage %&gt;
</code></pre>

<p>Why wouldn't the DisplayMessage property be added to the ViewData (ie. ViewData["DisplayMessage"]) collection without strong typing the user control?  Is this by design?  Wouldn't it make sense that ViewData would contain a key for "DisplayMessage"?</p>

[{'answer_id': 18830, 'author': 'Ryan Eastabrook', 'author_id': 105, 'author_profile': 'https://Stackoverflow.com/users/105', 'pm_score': 2, 'selected': False, 'text': '<p>Of course after I create this question I immediately find the answer after a few more searches on Google</p>\n\n<p><a href="http://forums.asp.net/t/1197059.aspx" rel="nofollow noreferrer">http://forums.asp.net/t/1197059.aspx</a></p>\n\n<p>Apparently this happens because of the wrapper class.  Even so, it seems like any property passed should get added to the ViewData collection by default.</p>\n\n<p>I really need to stop answering my own questions :(</p>\n'}, {'answer_id': 31726, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 4, 'selected': True, 'text': '<p>The method </p>\n\n<pre><code>ViewData.Eval("DisplayMessage") \n</code></pre>\n\n<p>should work for you.</p>\n'}]
['https://Stackoverflow.com/questions/18787', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/105/']