I have created an EditorTemplate to be in charge of rendering a collection of phone number edits for a couple of my views in my latest project. My EditorTemplate excpects a List of PhoneNumberModel.
It seems as though all of my element names that are tied to the PhoneNumberModel are being give an extra period PhoneNumbers.[index].[PropertyName] so my element names are looking like this: PhoneNumbers.[0].AreaCode
I just tested this in another EditorTemplate that had a Model that was of type Address and the AddressModel had a property called states. When I used this following line of code it correctly generated the element name: <%: Html.TextBoxFor(m => m.States[i].StateAbbreviation)%>
I am not really sure as to where the issue but I am guessing it lies within the way the LambdaExpression generates the name for the strongly typed html helper. Below is my Editor Template code.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList<UI.Models.PhoneNumberModel>>" %>
<% if (Model != null && Model.Count > 0) { %>
<table class="ui-helper-reset input-layout" cellpadding="0" cellspacing="0">
<% for (int i = 0; i < Model.Count; i++ )
{ %>
<tr <% if ((Model.Count - 1) == i) { %> class="last-row" <% } %>>
<td class="label-cell">
<% if (Model[i].Id > 0)
{ %>
<%: Html.HiddenFor(m => m[i].Id)%>
<% } %>
<%: Html.HiddenFor(m => m[i].PhoneNumberTypeId)%>
<%: (BusinessEntities.Enumerations.PhoneNumberTypes)Model[i].PhoneNumberTypeId%>:
</td>
<td>
(
<%: Html.TextBoxFor(m => m[i].AreaCode, new { @style = "width: 30px;", @maxLength = "3" })%>
)
<%: Html.TextBoxFor(m => m[i].Prefix, new { @style = "width: 30px;", @maxLength = "3" })%>
-
<%: Html.TextBoxFor(m => m[i].Suffix, new { @style = "width: 37px;", @maxLength = "4" })%>
ext.<%: Html.TextBoxFor(m => m[i].Extension, new { @style = "width: 80px;", @maxLength = "10" })%>
</td>
<td class="label-cell">
<%: Html.LabelFor(m => m[i].IsPrimary)%>
</td>
<td>
<%: Html.CheckBoxFor(m => m[i].IsPrimary, Model[i].IsPrimary)%>
</td>
</tr>
<% } %>
</table>
<% } %>