title: Extend an object from ViewData in MVC HtmlHelpers
body: <p>I am building an ajax form using the MVC Ajax Helpers: <a href="http://msdn.microsoft.com/en-us/library/dd505013.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd505013.aspx</a></p>
  
  <p>The code looks similar to:</p>
  
  <pre><code>Ajax.BeginForm("ActionName", "ControllerName",
      new {
              SomeProperty = (ViewData["SomeObject"] as SomeClass).SomeProperty,
              AnotherProperty = (ViewData["SomeObject"] as SomeClass).AnotherProperty,
              AllTheProperties = (ViewData["SomeObject"] as SomeClass).AllTheProperties,
              otherProperty= ViewData["otherObject"]
          },
    new AjaxOptions {},
    new {id = "anHtmlId"} );
  </code></pre>
  
  <p>but there are plenty of more properties in <code>ViewData["SomeObject"]</code> though.</p>
  
  <p>I would like to add <code>ViewData["otherObject"]</code> to the routeData object simply with as few lines as possible and do not want have all of the properties of <code>someObject</code> laid out individually so that I can add properties to it without having to revisit this code in the view.</p>
  
  <p>Essentially "merging" these objects to pass as the routeData parameter would be useful.</p>
  
  <hr>
  
  <p><strong>Update:</strong> an idea:</p>
  
  <pre><code>Ajax.BeginForm("ActionName", "ControllerName",
      ViewData["SomeObject"].addThePropertiesOf(ViewData["otherObject"]),
    new AjaxOptions {},
    new {id = "anHtmlId"} );
  </code></pre>
  
  <p>Where <code>addThePropertiesOf()</code> returns a new merged object. I wouldn't like to use the expensive bits of reflection otherwise this doesn't seem performant.</p>