2010-03-09 24 views
2

我在我的模型以下類:在MVC 2中使用Html.EditorFor時如何設置字段的外觀順序?

public abstract class Entity : IEntity 
{ 
    [ScaffoldColumn(false)] 
    public int Id { get; set; } 
    [Required,StringLength(500)] 
    public string Name { get; set; } 
} 

public class Model : SortableEntity 
{ 
    [Required] 
    public ModelType Type { get; set; } 
    [ListRequired] 
    public List<Producer> Producers { get; set; } 
    public List<PrintArea> PrintAreas { get; set; } 
    public List<Color> Colors { get; set; } 
} 

要顯示在視圖中的 「模式」 I類只需調用Html.EditorFor(型號=>模型),但是基類的「名稱」屬性最後呈現,這不是所需的行爲。

是否有可能以某種方式顯示顯示字段的順序?

+2

這裏有一個體面的解決方案http://blog.maartenballiauw.be/post/2010/01/11/Ordering-fields-in-ASPNET-MVC-2-templated-helpers.aspx – duckworth 2010-05-26 20:40:33

回答

0

我已經無法找到一個屬性,所以你的選擇是:

1)創建一個,然後修改基礎Object.ascx模板考慮到它,或 2)創建一個自定義的編輯器模板,可以按照您想要的順序顯式地放入東西。

+0

聽起來很合理。結束放棄基類(Entity,SortableEntity等),創建接口(IEntity,ISortableEntity)並在所有類中手動添加相應的屬性。 – AndreyM 2010-03-09 20:00:03

相關問題