title: ForEach with EditorFor
body: <p>I have got an Entity model which contains a collection of Message objects which are of the type Message which has several properties, including content, MessageID, from, and to.</p>
  
  <p>I have created an EditorTemplate for type Message, however, I cannot get it to display the contents of the Messages collection.</p>
  
  <p>There are no errors, but nothing is output.</p>
  
  <p>Please note that the view code is from an EditorTemplate for the parent Talkback class. Can you have an EditorTemplate calling another EditorTemplate for a child collection?</p>
  
  <p>Both the Talkback and Message class are generated by Entity framework from an existing database.</p>
  
  <p>View code:</p>
  
  <pre><code>        &lt;% foreach (TalkbackEntityTest.Message msg in Model.Messages)
      { 
             Html.EditorFor(x=&gt; msg, "Message"); 
      } %&gt;
  </code></pre>
  
  <p>This is my template code. It is the standard auto-generated view code with some minor changes.</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;TalkbackEntityTest.Message&gt;" %&gt;
  
      &lt;%: Html.ValidationSummary(true) %&gt;
  
      &lt;fieldset&gt;
          &lt;legend&gt;Fields&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.MessageID) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.MessageID) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.MessageID) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.acad_period) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.acad_period) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.acad_period) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.talkback_id) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.talkback_id) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.talkback_id) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.From) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.From) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.From) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.To) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.To) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.To) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.SentDatetime) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.SentDatetime, String.Format("{0:g}", Model.SentDatetime)) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.SentDatetime) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.content) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.content) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.content) %&gt;
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              &lt;%: Html.LabelFor(model =&gt; model.MessageTypeID) %&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;%: Html.TextBoxFor(model =&gt; model.MessageTypeID) %&gt;
              &lt;%: Html.ValidationMessageFor(model =&gt; model.MessageTypeID) %&gt;
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Save" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  </code></pre>
  
  <p>There is definitely content in the Message collection as, if I remove EditorFor and put in response.write on the content property of the Message class, I get the content field for 3 Message objects on the page, which is exactly as expected.</p>