I have an Entity model that contains a collection of Message objects that are of type Message, which has several properties, including content, MessageID, from and to.
I created an EditorTemplate for the Message type, however I cannot get it to display the contents of the Messages collection.
There are no errors, but nothing is displayed.
Note that the view code is from the EditorTemplate for the Talkback parent class. Can you have an EditorTemplate call another EditorTemplate for a child collection?
Both Talkback and Message classes are generated by the Entity framework from an existing database.
View code:
<% foreach (TalkbackEntityTest.Message msg in Model.Messages)
{
Html.EditorFor(x=> msg, "Message");
} %>
This is my template code. This is a standard automated code with a few changes.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TalkbackEntityTest.Message>" %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.MessageID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.MessageID) %>
<%: Html.ValidationMessageFor(model => model.MessageID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.acad_period) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.acad_period) %>
<%: Html.ValidationMessageFor(model => model.acad_period) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.talkback_id) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.talkback_id) %>
<%: Html.ValidationMessageFor(model => model.talkback_id) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.From) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.From) %>
<%: Html.ValidationMessageFor(model => model.From) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.To) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.To) %>
<%: Html.ValidationMessageFor(model => model.To) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.SentDatetime) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.SentDatetime, String.Format("{0:g}", Model.SentDatetime)) %>
<%: Html.ValidationMessageFor(model => model.SentDatetime) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.content) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.content) %>
<%: Html.ValidationMessageFor(model => model.content) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.MessageTypeID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.MessageTypeID) %>
<%: Html.ValidationMessageFor(model => model.MessageTypeID) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
, , EditFor response.write content Message, 3 Message , , .