title: MVC OrderBy EditorFor IEnumerable
body: <p>I have just registered, and this is my first post, so please bear with me if the question is not the best.  I have had a look about and can't find an answer that suits my requirements; this is possibly because it's not possible to achieve what I want.</p>
  
  <p>I have a partial view which pulls through an IEnumerable list of EditorFor fields from a viewmodel:</p>
  
  <pre><code>@model DocumentViewModelContainer
  @Html.EditorFor(m =&gt; m.Document.Metadata)
  </code></pre>
  
  <p>The DocumentViewModelContainer has the following code:</p>
  
  <pre><code>public class DocumentViewModelContainer
  {
      public DocumentViewModel Document
      {
          get;
          set;
      }
  </code></pre>
  
  <p>The DocumentViewModel has the following code:</p>
  
  <pre><code>public class DocumentViewModel
  {
      public IEnumerable&lt;DocumentMetadataFieldViewModel&gt; Metadata
          {
              get;
              set;
          }
  }
  </code></pre>
  
  <p>There's a ton of other objects in both view models that I've left out as being irrelevant in this question.  The DocumentMetadataFieldViewModel is made up of several fields of standard types (int, strings etc.)</p>
  
  <p>What I'm trying to achieve is adding an OrderBy to this list pulled back by ordering by an object in the bottom view model, such as follows:</p>
  
  <pre><code>@model DocumentViewModelContainer
  @Html.EditorFor(m =&gt; m.Document.Metadata.OrderBy(i =&gt; i.InstanceFieldOrder))
  </code></pre>
  
  <p>However this gives the error:</p>
  
  <pre><code>System.InvalidOperationException : Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
  </code></pre>
  
  <p>I'm not only very new to MVC, but to C# in general; this project has had me learning the language on the fly, so please play nice :)</p>
  
  <p>Thanks,</p>
  
  <p>Mark</p>