title: Iterating over properties of a lambda expression
body: <p>I am attempting to genericise a complex control which is used in my website quite often but with different fields. The functionality in the control is always the same, it's just the underlying fields which change.</p>
  
  <p>To achieve the method of showing different fields I am attempting to create a HTMLHelper extension which accepts a <code>Expression&lt;Func&lt;TModel,TProperty&gt;&gt;</code> as a parameter, which would contain the properties of a class required for display in the control. For example:</p>
  
  <p>The view:</p>
  
  <pre><code>@model Project.Core.Page
  @Html.MyHelper(p =&gt; new { p.Author.Name, p.Author.Location, p.Author.Age });
  </code></pre>
  
  <p>It's the extension I'm having problems with - how can I iterate over the provided params in the lambda to provide each with a <code>TextBoxFor()</code>, or even manually create a <code>input</code> element and populate it with the <code>value</code> and <code>name</code> of the lambda parameter?</p>
  
  <p>The extention in psuedo:</p>
  
  <pre><code>public static MvcHtmlString MyHelper&lt;TModel,TProperty&gt;(
      this HtmlHelper&lt;TModel&gt; helper, 
      Expression&lt;Func&lt;TModel,TProperty&gt;&gt; expression) {
      foreach (var parameter in expression.???) {
          // helper.TextBoxFor(???) 
          // TagBuilder("input").Attributes("name", expression.???)
      }
  }
  </code></pre>
  
  <p>I feel like I've been staring at this for far too long, and I'm also feeling there's a more simple way I'm overlooking of achieving this.</p>
  
  <p>Any help is greatly appreciated. If you need further details, or I've missed something important, let me know.</p>