[英]How to set order of appearance for fields when using Html.EditorFor in MVC 2?
I have the following classes in my Model: 我的模型中有以下课程:
public abstract class Entity : IEntity
{
[ScaffoldColumn(false)]
public int Id { get; set; }
[Required,StringLength(500)]
public string Name { get; set; }
}
and 和
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; }
}
To display the "Model" class in the view I simply call Html.EditorFor(model=>model), but the "Name" property of the base class is rendered last, which is not the desired behaviour. 要在视图中显示“ Model”类,我只需调用Html.EditorFor(model => model),但是最后呈现基类的“ Name”属性,这不是所需的行为。
Is it possible to influenece on the order of displayed fields somehow? 是否可以某种方式影响显示字段的顺序?
I've not been able to find an attribute for that, so your options are: 我无法为此找到属性,因此您可以选择:
1) create one, and then revise the base Object.ascx template to account for it, or 2) create a custom editor template for your classes that explicitly put stuff in the order you want. 1)创建一个,然后修改基本的Object.ascx模板以解决该问题,或2)为您的类创建一个自定义编辑器模板,该模板将内容按所需顺序显式放置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.