Using EditorFor( model lamda, "viewTemplateName"), my output is completely not as expected. This doesn't produce any errors, but it is rendering output without markup. What am I doing wrong?
The Output:
HarryTomRichard
The Expected Output (I need to figure out how to render the List [] indexes on id too but not to that problem yet):
<table>
<tr><td><span><input type="Text" id="Name[0]" value="Harry" /></span></td></tr>
<tr><td><span><input type="Text" id="Name[1]" value="Tom" /></span></td></tr>
<tr><td><span><input type="Text" id="Name[2]" value="Richard" /></span></td></tr>
</table>
My Classes:
namespace Marcs.Models {
public class Student { public string Name { get; set; } }
public class Classroom { public List<Student> Students { get; set; }
}
My Controller:
public ActionResult Index() {
var myStudents = new List<Student>();
myStudents.Add(new Student { Name = "Harry" });
myStudents.Add(new Student { Name = "Tom" });
myStudents.Add(new Student { Name = "Richard" });
var myClass = new Classroom {Students = myStudents};
return View(myClass);
}
My Index View:
Inherits="System.Web.Mvc.ViewPage<Marcs.Models.Classroom>" %>
<% using (Html.BeginForm()) { %>
<%= Html.EditorFor(m => m.Students, "Classroom") %>
<input type="submit" value="Save" />
<% } %>
My Classroom Template (notice the m => item so I can use the item, not the model):
Inherits="System.Web.Mvc.ViewUserControl<List<Marcs.Models.Student>>" %>
<table>
<% foreach (Marcs.Models.Student item in Model)
{ %><tr><td><%= Html.EditorFor(m => item, "Student")%></td></tr><%
} %>
</table>
My Student Template:
Inherits="System.Web.Mvc.ViewUserControl<Marcs.Models.Student>"
%><span><%= Html.Encode( Html.EditorFor( m => m.Name)) %></span>