Html.EditorForModel doesnt render complex types

2020-06-23 05:53发布

问题:

I have a class with this property

        [Display(Name = "Estado Civil"),UIHint("EstadoCivil"),ScaffoldColumn(true)]
    public virtual EstadoCivil EstadoCivil { get; set; }

then in my view I call Html.EditForModel(), however the property doesnt show, I even have the template in my Controller's views folder and then "EditorTemplates", I'm using razor and my view is not strongly typed, would that have something to do?

回答1:

By default editor/display templates descent only one level in the object hierarchy. Here's an excellent blog post from Brad Wilson which describes how you could have an editor template which descends more than 1 level.