title: ASP.Net MVC 3 Razor: how to create and pass info to a dynamic layout
body: <p>In other languages (PHP/Python), I am used to creating a class which represents a given HTML page layout.  These classes can have an unlimited number of attributes and dynamic features, such as Navigation (multi level), error messages, info messages, footer text, etc... Most of these items have defaults, but may be overridden on a per-page level.  For example:</p>
  
  <pre><code>Layout = MainPage()
  
  Layout.Title = "Google Image Search"
  
  Layout.Nav1.Add("Google", "http://www.google.com", Selected=True)
  Layout.Nav1.Add("Yahoo", "http://www.yahoo.com")
  Layout.Nav1.Add("Bing", "http://www.bing.com")
  
  Layout.Nav2.Add("Google Image Search", "http://......", Selected=True)
  Layout.Nav2.Add("Google Shopping Search", "http://......")
  Layout.Nav2.Add("Google Video Search", "http://......")
  Layout.Nav2.Add("Google Web Search", "http://......")
  </code></pre>
  
  <p>or, handling errors:</p>
  
  <pre><code>try:
     # do something
  except ValidationError as e:
     Layout.Error.Add(e)
  </code></pre>
  
  <p>or a php example: </p>
  
  <pre><code>$Layout-&gt;Info[] = "Your changes have been saved!";
  </code></pre>
  
  <p><strong>My question is: how do I implement similar functionality into ASP.Net MVC 3 Razor (VB)?</strong></p>
  
  <p>So far, I have been able to see how you can use <code>ViewData</code> to pass various bits of data to a view.  Also, I have been working with strongly typed views.</p>
  
  <p>Frankly, I'm not sure who's job it is to have this logic, the controller or the view (or is there a model that should be in there somewhere).</p>
  
  <p>Here is a summary of what I am shooting for:</p>
  
  <ol>
  <li>A single place to initialize the default values for the layout (like the first layer of navigation, etc...)</li>
  <li>Strongly typed attributes, such as <code>Public Readonly Property Nav1 as List(of NavElement)</code></li>
  <li>And a single place to render these layout elements (I assume <code>_Layout.vbhtml</code>)</li>
  </ol>
  
  <p>Please forgive the here-and-there of this post...  I'm trying to figure out the "right way" it's done on a platform that is both new (Razor) and new to me (ASP.Net MVC).</p>
  
  <p>General advise very welcome!</p>