Html.Editor() helper in ASP.NET MVC 3 does not work as expected with array in model
        Posted  
        
            by 
                SlimShaggy
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by SlimShaggy
        
        
        
        Published on 2012-03-30T17:20:54Z
        Indexed on 
            2012/03/30
            17:29 UTC
        
        
        Read the original article
        Hit count: 207
        
In my ASP.NET MVC 3 application I have classes like the following:
public class Localization<T>
{
    public int VersionID { get; set; }
    public T Value { get; set; }
    ...
}
public class Localizable<T>
{
    public Localization<T>[] Name { get; set; }
    ...
}
Then, I have the following view:
@model dynamic
...
@for (int i = 0; i < VersionCount; i++)
{
    ...
    @Html.Editor(string.Format("Name[{0}.Value", i))
    ...
}
Now, when I display this view, passing a subclass of Localizable<string> as the model, the textboxes for the strings are rendered, but they are empty. If I replace @Html.Editor(string.Format("Name[{0}.Value", i)) with @InputExtensions.TextBox(Html, string.Format("Name[{0}].Value", i), Model.Name[i].Value), the textboxes are correctly filled with values from the model. However, using TextBox instead of Editor is not an option for me, because I want to use different editor templates for different types of T. So, what am I doing wrong, or is it a bug in MVC, and is there any workaround?
© Stack Overflow or respective owner